示例#1
0
        public TEProjectUnitModel Get(int id)
        {
            TEProjects_UNIT    item  = db.TEProjects_UNIT.Find(id);
            TEProjectUnitModel model = new TEProjectUnitModel();

            TETransformEntityNModel translator = new TETransformEntityNModel();

            model = translator.TransformAtoB(item, model);
            #region Commented due to entity change
            //if (item.PROJECT_ID.Value > 0)
            //{
            //    TEProject pro = db.TEProjects.Find(item.PROJECT_ID.Value);
            //    if (pro != null)
            //        model.Project = new TEProject
            //        {
            //            Uniqueid = pro.Uniqueid,
            //            ProjectCode = pro.ProjectCode,
            //            ProjectName = pro.ProjectName,
            //            ProjectShortName = pro.ProjectShortName,
            //            ProjectStatus = pro.ProjectStatus,
            //            IsNewProject = pro.IsNewProject,
            //            City = pro.City,
            //            COLOURCODE = pro.COLOURCODE,
            //        };

            //}
            #endregion
            if (item.TOWERID != null)
            {
                TEProjects_TOWER tower = db.TEProjects_TOWER.Find(item.TOWERID);
                if (tower != null)
                {
                    model.Tower = new TEProjects_TOWER
                    {
                        Uniqueid    = tower.Uniqueid,
                        TOWERNAME   = tower.TOWERNAME,
                        TOWERCODE   = tower.TOWERCODE,
                        DESCRIPTION = tower.DESCRIPTION
                    }
                }
                ;
            }
            return(model);
        }
示例#2
0
        public TEProjects_UNIT Post(TEProjects_UNIT value)
        {
            TEProjects_UNIT result = value;

            if (!(value.Uniqueid + "".Length > 0))
            {
                result.CreatedOn      = System.DateTime.Now;
                result.LastModifiedOn = System.DateTime.Now;
                result = db.TEProjects_UNIT.Add(value);
            }
            else
            {
                db = new TEHRIS_DevEntities();
                db.TEProjects_UNIT.Attach(value);

                foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties())
                {
                    string propname = item.Name;
                    if (propname.ToLower() == "createdon")
                    {
                        continue;
                    }
                    object propValue = item.GetValue(value);
                    if (propValue != null || Convert.ToString(propValue).Length != 0)
                    {
                        db.Entry(value).Property(propname).IsModified = true;
                    }
                }

                value.LastModifiedOn = System.DateTime.Now;
                db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true;
            }

            db.SaveChanges();

            return(db.TEProjects_UNIT.Find(value.Uniqueid));
        }
        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");
        }
        public object SendContact(TEUnit_Onboarding value)
        {
            TEUnit_Onboarding unit     = db.TEUnit_Onboarding.Where(x => x.Uniqueid == value.Uniqueid).ToList().First();
            UserProfile       userinfo = db.UserProfiles.Where(x => x.UserId == unit.UserID).ToList().First();

            if (userinfo != null)
            {
                int?tower = 0;
                try
                {
                    TEProjects_UNIT projectunit = db.TEProjects_UNIT.Where(x => (x.PROJECT_ID == value.Project) &&
                                                                           (x.AREA == value.Unit)).ToList().First();
                    if (projectunit != null)
                    {
                        tower = projectunit.TOWERID;
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
                TEContact contact = new TEContact
                {
                    ApprovedBy = userinfo.CallName,
                    ApprovedOn = System.DateTime.Now,
                    CreatedBy  = userinfo.CallName,
                    CreatedOn  = System.DateTime.Now,
                    //Have to be dynamic...

                    IsDeleted               = false,
                    LastModifiedBy          = userinfo.CallName,
                    LastModifiedOn          = System.DateTime.UtcNow,
                    Projectid               = value.Project,
                    Towerid                 = tower,
                    Unitid                  = value.Unit,
                    Mobile                  = userinfo.Phone,
                    Emailid                 = userinfo.email,
                    DOB                     = System.DateTime.Now,
                    DOM                     = System.DateTime.Now,
                    Type                    = "",
                    PrefferedContact        = "",
                    PrefferedMode           = "",
                    ISProfileSPublic        = false,
                    IsAdvertise             = false,
                    Photo                   = userinfo.photo,
                    Salutation              = "",
                    FirstName               = "",
                    MiddleName              = "",
                    LastName                = "",
                    CallName                = userinfo.CallName,
                    ContactType             = "",
                    Nationality             = "",
                    CountryOfBirth          = "",
                    Age                     = 0,
                    Gender                  = "",
                    MaritalStatus           = "",
                    Category                = "",
                    Importance              = "",
                    PrefferedSaleConsultant = "",
                    TEOrganisation          = 0,
                    Status                  = value.Status,
                    //Type
                };
                return(db.TEContacts.Add(contact));
            }
            return("Success");
        }