public void InsertOrUpdate(EmailSentStatus emailsentstatus)
 {
     if (emailsentstatus.ID == default(long)) {
         // New entity
         context.EmailSentStatus.Add(emailsentstatus);
     } else {
         // Existing entity
         context.Entry(emailsentstatus).State = System.Data.Entity.EntityState.Modified;
     }
 }
        // GET api/FetchMails
        /// <summary>
        /// API to get email list
        /// Mahedee @20-03-14
        /// </summary>
        /// <returns></returns>
        public List<Mailer> Get()
        {
            List<Mailer> objOflstMailer = new List<Mailer>();
            
            //Dictionary<int, string> lstOfEmailSchedules = unitofWork.EmailSchedulerRepository.GetSchedulerList();

            //foreach (KeyValuePair<int,string> item in lstOfEmailSchedules)
            //{
            //    if (item.Key == 1)  //Do for "Remainder email for provide estimation"
            //    {
            //        //Do for "Remainder email for provide estimation"

            //       objOflstMailer = EstimationMail();
            //    }
            //}

           
            //objOflstMailer.Add(new Mailer { UseMailID = "*****@*****.**", HtmlMailBody = "This is a test mgs", MailSubject = "Hello msg" });

            List<EmailScheduler> emailschedulerlst = unitofWork.EmailSchedulerRepository.GetEmailSchedulerAll(); // This Method Return All the Schedule
            
            DateTime cdate = DateTime.Now;
            DateTime onlyDate = cdate.Date;
            TimeSpan ts1 = cdate.TimeOfDay;
            DateTime currentdateTime = onlyDate + ts1;

            List<EmailSentStatus> objOfEmailSent = new List<EmailSentStatus>();
            objOfEmailSent = unitofWork.EmailSentStatusRepository.GetEmailSentStatuseAll();


            foreach (var emailSchedule in emailschedulerlst) 
            {
                if (emailSchedule.SchedulerTitleID == 2) //This is for Daily Status mail
                {
                        //List<EmailSentStatus> objOfEmailSent = new List<EmailSentStatus>();
                        //objOfEmailSent = unitofWork.EmailSentStatusRepository.GetEmailSentStatuseAll();
                        
                        //DateTime cdate = DateTime.Now;
                        //DateTime onlyDate = cdate.Date;
                        //TimeSpan ts1 = cdate.TimeOfDay;
                        //DateTime currentdateTime = onlyDate + ts1;
                        
                        DateTime scheduleDateTime = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);

                        if (objOfEmailSent.Count > 0)
                        {
                            foreach (var ObjofList in objOfEmailSent)
                            {

                                bool emailStatus = unitofWork.EmailSentStatusRepository.EmailSentStatus(ObjofList.EmailSchedulerID, ObjofList.ScheduleTypeID, scheduleDateTime);
                                if (emailStatus == true && currentdateTime >= scheduleDateTime)
                                {
                                    continue;
                                }
                                else if(currentdateTime<=scheduleDateTime)
                                {
                                    continue;
                                }

                                else
                                {
                                    objOflstMailer = DailyTaskStatus(emailSchedule);
                                    //objOflstMailer.AddRange(DailyTaskStatusForCreator());

                                    if (objOflstMailer.Count >= 0)
                                    {

                                        EmailSentStatus objEmailSentStatus = new EmailSentStatus();
                                        objEmailSentStatus.EmailSchedulerID = 2;
                                        objEmailSentStatus.ScheduleTypeID = 1;
                                        DateTime date = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);
                                        TimeSpan ts = date.TimeOfDay;
                                        objEmailSentStatus.ScheduleDateTime = DateTime.Today.Add(ts);
                                        objEmailSentStatus.SentDateTime = DateTime.Now;
                                        objEmailSentStatus.SentStatus = true;
                                        objEmailSentStatus.ActionTime = DateTime.Now;

                                        unitofWork.EmailSentStatusRepository.InsertOrUpdate(objEmailSentStatus);
                                        unitofWork.Save();

                                    }
                                }
                            }
                        }

                        else 
                        {
                            if (currentdateTime >= scheduleDateTime) 
                            {
                                objOflstMailer = DailyTaskStatus(emailSchedule);
                                //objOflstMailer.AddRange(DailyTaskStatusForCreator());

                                if (objOflstMailer.Count >= 0)
                                {

                                    EmailSentStatus objEmailSentStatus = new EmailSentStatus();
                                    objEmailSentStatus.EmailSchedulerID = 2;
                                    objEmailSentStatus.ScheduleTypeID = 1;
                                    DateTime date = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);
                                    TimeSpan ts = date.TimeOfDay;
                                    objEmailSentStatus.ScheduleDateTime = DateTime.Today.Add(ts);
                                    objEmailSentStatus.SentDateTime = DateTime.Now;
                                    objEmailSentStatus.SentStatus = true;
                                    objEmailSentStatus.ActionTime = DateTime.Now;

                                    unitofWork.EmailSentStatusRepository.InsertOrUpdate(objEmailSentStatus);
                                    unitofWork.Save();

                                }
                            }                  
                        }
                           
                }

                else if (emailSchedule.SchedulerTitleID == 4) // This is for Notification Email
                {
                    DateTime scheduleDateTime = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);
                    //List<Notification> ListOfNotification = unitofWork.NotificationRepository.GetNotificationDetails(emailSchedule);              
  
                    if (objOfEmailSent.Count >0)
                    {

                        foreach (var objOfEmailSentStutusDet in objOfEmailSent) 
                        {

                            bool emailStatus = unitofWork.EmailSentStatusRepository.EmailSentStatus(objOfEmailSentStutusDet.EmailSchedulerID, objOfEmailSentStutusDet.ScheduleTypeID, scheduleDateTime);

                            if (emailStatus == true && currentdateTime>scheduleDateTime)
                            {
                                continue;
                            }
                            else if(currentdateTime<=scheduleDateTime)
                            {
                                continue;
                            }
                           
                            else
                            {
                                objOflstMailer = NotificationEmail(emailSchedule.ProjectID, scheduleDateTime); // Mail Function Call here

                                if (objOflstMailer.Count >= 0)
                                {
                                    EmailSentStatus objEmailSentStatus = new EmailSentStatus();
                                    objEmailSentStatus.EmailSchedulerID = 4;
                                    objEmailSentStatus.ScheduleTypeID = 1;
                                    DateTime date = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);
                                    TimeSpan ts = date.TimeOfDay;
                                    objEmailSentStatus.ScheduleDateTime = DateTime.Today.Add(ts);
                                    objEmailSentStatus.SentDateTime = DateTime.Now;
                                    objEmailSentStatus.SentStatus = true;
                                    objEmailSentStatus.ActionTime = DateTime.Now;

                                    unitofWork.EmailSentStatusRepository.InsertOrUpdate(objEmailSentStatus);
                                    unitofWork.Save();
                                }
                            }
                        }

                     
                    }
                    else 
                    {
                        if (currentdateTime >= scheduleDateTime) 
                        {
                            objOflstMailer = NotificationEmail(emailSchedule.ProjectID, scheduleDateTime); // Mail Function Call here

                            if (objOflstMailer.Count >= 0)
                            {
                                EmailSentStatus objEmailSentStatus = new EmailSentStatus();
                                objEmailSentStatus.EmailSchedulerID = 4;
                                objEmailSentStatus.ScheduleTypeID = 1;
                                DateTime date = DateTime.ParseExact(emailSchedule.ScheduledTime, "h:mm tt", CultureInfo.InvariantCulture);
                                TimeSpan ts = date.TimeOfDay;
                                objEmailSentStatus.ScheduleDateTime = DateTime.Today.Add(ts);
                                objEmailSentStatus.SentDateTime = DateTime.Now;
                                objEmailSentStatus.SentStatus = true;
                                objEmailSentStatus.ActionTime = DateTime.Now;

                                unitofWork.EmailSentStatusRepository.InsertOrUpdate(objEmailSentStatus);
                                unitofWork.Save();
                            }
                        }
                     
                    }

                  
                }


            }

            return objOflstMailer;
            //return new List<Mailer>();
        }