LogicNotification.cs 3.28 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ControlPanel.Interfaces.Strategys;
using ControlPanel.Models;
using ControlPanel.Models.Extend;
using ControlPanel.Interfaces.Reposytorys;
using ControlPanel.NHInplimentRepository;
using ControlPanel.Contexts;
using ControlPanel.ImplimentStrateges;

namespace ControlPanel.LogicLayers
{
    public class LogicNotification
    {


        public static LogicNotification instance = new LogicNotification();


        INotificationRepository _notificationrepository;

        public LogicNotification()
        {
            if (_notificationrepository == null)
                _notificationrepository = new NHNotificationRepository();


        }



        public int Count()
        {
            int count = 0;
            try
            {
                if (_notificationrepository == null)
                    _notificationrepository = new NHNotificationRepository();

                count = _notificationrepository.Count();

            }
            catch (Exception)
            {

            }

            return count;
        }
        
        
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public List<Notification> GetLog(int page, int start, int limit)
        {
            List<Notification> result = new List<Notification>();
            try
            {

                if (_notificationrepository == null)
                    _notificationrepository = new NHNotificationRepository();


             //   result = _notificationrepository.GetLog(start,limit*page).ToList();

                result = _notificationrepository.GetAll().ToList();

            }
            catch (Exception)
            {

            }

            return result;
        }



        public Notification GetNotificationByNumber(int number)
        {
            if (_notificationrepository == null)
                _notificationrepository = new NHNotificationRepository();

             return _notificationrepository.GetByNumber(number); 


        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void Add(Notification obj)
        {
            try
            {
                if (_notificationrepository == null)
                    _notificationrepository = new NHNotificationRepository();

                Notification objexist = _notificationrepository.GetByNumber(obj.number);

                if (objexist == null)
                {

                    _notificationrepository.Save(obj);
                }
                else
                {
                    objexist.notification = obj.notification;
                    Update(objexist);

                }
            }
            catch (Exception)
            {

            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void Update(Notification obj)
        {

            try
            {
                if (_notificationrepository == null)
                    _notificationrepository = new NHNotificationRepository();

                _notificationrepository.SaveUpdate(obj);
            }
            catch (Exception)
            {


            }

        }
     


    }
}