Example #1
0
        private void CreateDefaultData(CMS_Context context)
        {
            try
            {
                var hier = HierarchyData.HierarchyConfigs;

                /*-- Insert Employee --*/
                #region -- Employee --
                if (hier.Employees != null && hier.Employees.Count > 0)
                {
                    foreach (EmployeeConfigElement pro in hier.Employees)
                    {
                        var emp = new CMS_Employee()
                        {
                            Id             = Guid.NewGuid().ToString(),
                            Employee_Email = pro.Email,
                            Employee_Phone = "",
                            FirstName      = "FirstName",
                            LastName       = "LastName",
                            IsActive       = true,
                            BirthDate      = DateTime.Now,
                            UpdatedDate    = DateTime.Now,
                            CreatedDate    = DateTime.Now,
                            Password       = "******",
                            IsSupperAdmin  = true,
                        };
                        context.CMS_Employees.Add(emp);
                    }
                }
                #endregion


                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #2
0
        public bool CreateOrUpdate(CMS_EmployeeModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Employee
                            {
                                Id               = _Id,
                                BirthDate        = model.BirthDate,
                                CreatedBy        = model.CreatedBy,
                                CreatedDate      = DateTime.Now,
                                Employee_Address = model.Employee_Address,
                                Employee_Email   = model.Employee_Email,
                                Employee_IDCard  = model.Employee_IDCard,
                                Employee_Phone   = model.Employee_Phone,
                                FirstName        = model.FirstName,
                                IsActive         = model.IsActive,
                                LastName         = model.LastName,
                                Password         = model.Password,
                                UpdatedBy        = model.UpdatedBy,
                                UpdatedDate      = DateTime.Now,
                                ImageURL         = model.ImageURL,
                                Level            = model.Level,
                                Position         = model.Position,
                                LinkFB           = model.LinkFB,
                                LinkInstagram    = model.LinkInstagram,
                                LinkPinterest    = model.LinkPinterest,
                                LinkTwiter       = model.LinkTwiter
                            };
                            cxt.CMS_Employees.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Employees.Find(model.Id);
                            if (e != null)
                            {
                                e.BirthDate        = model.BirthDate;
                                e.UpdatedBy        = model.UpdatedBy;
                                e.Employee_Address = model.Employee_Address;
                                e.Employee_Email   = model.Employee_Email;
                                e.Employee_IDCard  = model.Employee_IDCard;
                                e.Employee_Phone   = model.Employee_Phone;
                                e.FirstName        = model.FirstName;
                                e.LastName         = model.LastName;
                                e.IsActive         = model.IsActive;
                                e.Password         = model.Password;
                                e.UpdatedDate      = DateTime.Now;
                                e.ImageURL         = model.ImageURL;
                                e.Position         = model.Position;
                                e.Level            = model.Level;
                                e.LinkTwiter       = model.LinkTwiter;
                                e.LinkPinterest    = model.LinkPinterest;
                                e.LinkInstagram    = model.LinkInstagram;
                                e.LinkFB           = model.LinkFB;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Lỗi hệ thống! Vui lòng load lại.";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Example #3
0
        public bool CreateOrUpdate(CMS_EmployeeModels model, ref string Id, ref string msg)
        {
            NSLog.Logger.Info("EmployeeCreateOrUpdate", model);
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                try
                {
                    if (string.IsNullOrEmpty(model.Id)) /* insert */
                    {
                        var _isExits = cxt.CMS_Employee.Any(x => x.Email.Equals(model.Email) && x.IsActive.HasValue && x.Status == (byte)Commons.EStatus.Actived);

                        if (_isExits)
                        {
                            msg    = "Địa chỉ email đã tồn tại";
                            Result = false;
                        }
                        else
                        {
                            Id = Guid.NewGuid().ToString();
                            var e = new CMS_Employee
                            {
                                ID            = Id,
                                Name          = model.Name,
                                RoleID        = model.RoleID,
                                Email         = model.Email,
                                Password      = model.Password,
                                IsActive      = model.IsActive,
                                Phone         = model.Phone,
                                PinCode       = model.PinCode,
                                Gender        = model.Gender,
                                Marital       = model.Marital,
                                HiredDate     = model.HiredDate,
                                BirthDate     = model.BirthDate,
                                Street        = model.Street,
                                City          = model.City,
                                Country       = model.Country,
                                ZipCode       = model.ZipCode,
                                ImageUrl      = model.ImageURL,
                                StoreID       = model.StoreID,
                                IsSupperAdmin = model.IsSupperAdmin,
                                Status        = (byte)Commons.EStatus.Actived,
                                CreatedDate   = DateTime.Now,
                                CreatedUser   = model.CreatedBy,
                                ModifiedUser  = model.CreatedBy,
                                LastModified  = DateTime.Now,
                                Quote         = model.Quote,
                            };
                            cxt.CMS_Employee.Add(e);
                        }
                    }
                    else /* updated */
                    {
                        var e = cxt.CMS_Employee.Find(model.Id);
                        if (e != null)
                        {
                            var _isExits = cxt.CMS_Employee.Any(x => x.Email.Equals(model.Email) && x.Status != (byte)Commons.EStatus.Actived && x.IsActive.HasValue && x.ID == model.Id);

                            if (!_isExits)
                            {
                                e.Name          = model.Name;
                                e.RoleID        = model.RoleID;
                                e.Email         = model.Email;
                                e.Password      = model.Password;
                                e.IsActive      = model.IsActive;
                                e.Phone         = model.Phone;
                                e.PinCode       = model.PinCode;
                                e.Gender        = model.Gender;
                                e.Marital       = model.Marital;
                                e.HiredDate     = model.HiredDate;
                                e.BirthDate     = model.BirthDate;
                                e.Street        = model.Street;
                                e.City          = model.City;
                                e.Country       = model.Country;
                                e.ZipCode       = model.ZipCode;
                                e.ImageUrl      = model.ImageURL;
                                e.StoreID       = model.StoreID;
                                e.IsSupperAdmin = model.IsSupperAdmin;
                                e.Status        = (byte)Commons.EStatus.Actived;
                                e.ModifiedUser  = model.CreatedBy;
                                e.LastModified  = DateTime.Now;
                                e.Quote         = model.Quote;
                            }
                            else
                            {
                                msg    = "Địa chỉ email đã tồn tại";
                                Result = false;
                            }
                        }
                        else
                        {
                            Result = false;
                            msg    = "Unable to find Discount.";
                        }
                    }

                    cxt.SaveChanges();
                    NSLog.Logger.Info("ResponseEmployeeCreateOrUpdate", new { Result, msg });
                }
                catch (Exception ex)
                {
                    Result = false;
                    msg    = "System Error.";
                    NSLog.Logger.Error("ErrorEmployeeCreateOrUpdate", ex);
                }
            }
            return(Result);
        }
Example #4
0
        public bool CreateOrUpdate(CMS_EmployeeModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Employee
                            {
                                Id               = _Id,
                                BirthDate        = model.BirthDate,
                                CreatedBy        = model.CreatedBy,
                                CreatedDate      = DateTime.Now,
                                Employee_Address = model.Employee_Address,
                                Employee_Email   = model.Employee_Email,
                                Employee_IDCard  = model.Employee_IDCard,
                                Employee_Phone   = model.Employee_Phone,
                                FirstName        = model.FirstName,
                                IsActive         = model.IsActive,
                                LastName         = model.LastName,
                                Password         = model.Password,
                                UpdatedBy        = model.UpdatedBy,
                                UpdatedDate      = DateTime.Now,
                                ImageURL         = model.ImageURL
                            };
                            cxt.CMS_Employee.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Employee.Find(model.Id);
                            if (e != null)
                            {
                                e.BirthDate        = model.BirthDate;
                                e.UpdatedBy        = model.UpdatedBy;
                                e.Employee_Address = model.Employee_Address;
                                e.Employee_Email   = model.Employee_Email;
                                e.Employee_IDCard  = model.Employee_IDCard;
                                e.Employee_Phone   = model.Employee_Phone;
                                e.FirstName        = model.FirstName;
                                e.LastName         = model.LastName;
                                e.IsActive         = model.IsActive;
                                e.Password         = model.Password;
                                e.UpdatedDate      = DateTime.Now;
                                e.ImageURL         = model.ImageURL;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }