private TENotification SendNotification(TENotificationModel value)
        {
            var    usr          = db.UserProfiles.Where(x => x.UserId == Convert.ToInt32(value.SendBy)).FirstOrDefault();
            string description1 = "Issue: " + value.description + " " + usr.CallName.ToString();

            TENotification notify = new TENotification
            {
                ApprovedBy = value.ApprovedBy,
                ApprovedOn = System.DateTime.UtcNow,
                CreatedBy  = value.CreatedBy,
                CreatedOn  = System.DateTime.UtcNow,
                //Have to be dynamic...

                IsDeleted      = false,
                LastModifiedBy = value.ApprovedBy,
                LastModifiedOn = System.DateTime.UtcNow,

                Name        = "Issue: " + value.Status,
                description = description1,
                ReceivedBy  = value.ReceivedBy,
                SendBy      = value.SendBy,
                ReadStatus  = false,
                Status      = value.Status,
                //Type
            };

            var usrtype = (from usrs in db.UserProfiles
                           join tebas in db.TEEmpBasicInfoes on usrs.UserName equals tebas.UserId
                           where (usrs.UserId == Convert.ToInt32(value.SendBy))
                           select usrs.UserId).Distinct().FirstOrDefault();
            string apptype = "Fugue";

            if (usrtype == null)
            {
                apptype = "Yellow";
            }
            string res = "";

            if (usr.AndroidToken != null)
            {
                try
                {
                    TECommonLogicLayer.TEPushNotification tepush = new TECommonLogicLayer.TEPushNotification();
                    //tepush.SendNotification_Android("APA91bEWoz9U6m9VK-oBW1Jy-EIT6Fa9_xnWTOIyVfu-pdXpemMrahsiDW3A2MFMff9FuwKpV-EJ1-N4pfctx3EM2rnX1wAgGKIBfS1iLdCvus1VgYwpDbA", "Issue: " + value.Status.ToString(), "Fugue");
                    res = tepush.SendNotification_Android(usr.AndroidToken.ToString(), description1, apptype);

                    //AndroidNotification.Notification tepushandroid = new AndroidNotification.Notification();
                    //res=tepushandroid.AndroidNotification(usr.AndroidToken.ToString(), description1);
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
            if (usr.IosToken != null)
            {
                try
                {
                    TECommonLogicLayer.TEPushNotification tepush = new TECommonLogicLayer.TEPushNotification();
                    //tepush.SendNotification_IOS("0c11cdc92d14b96d6f309cc661c4cd36abe9cb1f38bccf4019de31b6cf97992b", "Issue: " + value.Status.ToString(), "Yellow");
                    tepush.SendNotification_IOS(usr.IosToken.ToString(), description1, apptype);
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }

            return(new TENotificationsController().AddNotifications(notify));
        }
        public object SendNotifications(TENotificationModel value)
        {
            try
            {
                TEProjects_UNIT ProjectUnit = db.TEProjects_UNIT.Where(x => (x.PROJECT_ID == value.Project) &&
                                                                       (x.TOWERID == Convert.ToInt32(value.Tower)) &&
                                                                       (x.AREA == value.unit)).ToList().First();
                if (ProjectUnit != null)
                {
                    List <TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project) &&
                                                                   (x.Towerid == value.Tower) &&
                                                                   (x.Unitid == value.unit)).ToList();
                    if (contact != null)
                    {
                        foreach (var item in contact)
                        {
                            UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                            if (userprof != null)
                            {
                                value.ReceivedBy = userprof.UserId;
                                value.Status     = "Active";
                                SendNotification(value);
                            }
                        }
                    }
                }
                else
                {
                    List <TEProjects_TOWER> ProjectTower = db.TEProjects_TOWER.Where(x => (x.PROJECT_ID == value.Project) &&
                                                                                     (x.Uniqueid == Convert.ToInt32(value.Tower))).ToList();
                    if (ProjectTower != null)
                    {
                        List <TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project) &&
                                                                       (x.Towerid == value.Tower)).ToList();
                        if (contact != null)
                        {
                            foreach (var item in contact)
                            {
                                UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                                if (userprof != null)
                                {
                                    value.ReceivedBy = userprof.UserId;
                                    value.Status     = "Active";
                                    SendNotification(value);
                                }
                            }
                        }
                    }
                    else
                    {
                        #region Commented due to entity change
                        //List<TEProject> Project = db.TEProjects.Where(x => (x.Uniqueid == value.Project)).ToList();
                        //if (ProjectTower != null)
                        //{
                        //    List<TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project)).ToList();
                        //    if (contact != null)
                        //    {
                        //        foreach (var item in contact)
                        //        {
                        //            UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                        //            if (userprof != null)
                        //            {
                        //                value.ReceivedBy = userprof.UserId;
                        //                value.Status = "Active";
                        //                SendNotification(value);
                        //            }
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    List <TEProjects_TOWER> ProjectTower = db.TEProjects_TOWER.Where(x => (x.PROJECT_ID == value.Project) &&
                                                                                     (x.Uniqueid == Convert.ToInt32(value.Tower))).ToList();
                    if (ProjectTower != null)
                    {
                        List <TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project) &&
                                                                       (x.Towerid == value.Tower)).ToList();
                        if (contact != null)
                        {
                            foreach (var item in contact)
                            {
                                UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                                if (userprof != null)
                                {
                                    value.ReceivedBy = userprof.UserId;
                                    value.Status     = "Active";
                                    SendNotification(value);
                                }
                            }
                        }
                    }
                    else
                    {
                        #region Commented due to entity change
                        //List<TEProject> Project = db.TEProjects.Where(x => (x.Uniqueid == value.Project)).ToList();
                        //if (Project != null)
                        //{
                        //    List<TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project)).ToList();
                        //    if (contact != null)
                        //    {
                        //        foreach (var item in contact)
                        //        {
                        //            UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                        //            if (userprof != null)
                        //            {
                        //                value.ReceivedBy = userprof.UserId;
                        //                value.Status = "Active";
                        //                SendNotification(value);
                        //            }
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                }
                catch (Exception ex1)
                {
                    #region Commented due to entity change
                    //try
                    //{

                    //List<TEProject> Project = db.TEProjects.Where(x => (x.Uniqueid == value.Project)).ToList();
                    //if (Project != null)
                    //{
                    //    List<TEContact> contact = db.TEContacts.Where(x => (x.Projectid == value.Project)).ToList();
                    //    if (contact != null)
                    //    {
                    //        foreach (var item in contact)
                    //        {
                    //            UserProfile userprof = db.UserProfiles.Where(x => (x.email == item.Emailid)).ToList().First();
                    //            if (userprof != null)
                    //            {
                    //                value.ReceivedBy = userprof.UserId;
                    //                value.Status = "Active";
                    //                SendNotification(value);
                    //            }
                    //        }
                    //    }

                    //    }
                    //}
                    //catch(Exception ex2)
                    //{
                    //    db.ApplicationErrorLogs.Add(
                    //        new ApplicationErrorLog
                    //        {
                    //            Error = ex.Message,
                    //            ExceptionDateTime = System.DateTime.Now,
                    //            InnerException = ex.InnerException != null ? ex.InnerException.Message : "",
                    //            Source = "From TENotifications API | AddNotifications | " + this.GetType().ToString(),
                    //            Stacktrace = ex.StackTrace
                    //        }
                    //        );
                    //}
                    #endregion
                }
            }

            db.SaveChanges();
            return("success");
        }