public ActionResult Edit(CMS_EmployeeModels model)
        {
            var temp = model.ImageURL;

            try
            {
                byte[] photoByte = null;
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                if (!string.IsNullOrEmpty(model.ImageURL))
                {
                    model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace("Employees/", "").Replace(Commons.Image268_297, "");
                    temp           = model.ImageURL;
                }

                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }

                var msg = "";
                model.Password = CommonHelper.Encrypt(model.Password);
                var result = _factory.CreateOrUpdate(model, ref msg);
                if (result)
                {
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        if (System.IO.File.Exists(Server.MapPath("~/Uploads/Employees/" + temp)))
                        {
                            ImageHelper.Me.TryDeleteImageUpdated(Server.MapPath("~/Uploads/Employees/" + temp));
                        }

                        var          path = Server.MapPath("~/Uploads/Employees/" + model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);

                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte, 400, Commons.WidthEmp, Commons.HeightEmp);
                    }
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("FirstName", msg);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Edit", model));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Edit", model));
            }
        }
 public ActionResult Delete(CMS_EmployeeModels model)
 {
     try
     {
         ModelState.Clear();
         if (!ModelState.IsValid)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         var msg    = "";
         var result = _factory.Delete(model.Id, ref msg);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("FirstName", msg);
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
     catch (Exception ex)
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Пример #3
0
        public ActionResult Create()
        {
            CMS_EmployeeModels model = new CMS_EmployeeModels();

            model.IsActive = true;
            return(PartialView("_Create", model));
        }
Пример #4
0
        public ActionResult Create(CMS_EmployeeModels model)
        {
            try
            {
                byte[] photoByte = null;
                if (!model.Password.Trim().ToLower().Equals(model.ConfirmPassword.ToString().Trim().ToLower()))
                {
                    ModelState.AddModelError("ConfirmPassword", "Làm ơn xác nhận lại mật khẩu!");
                }
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Create", model));
                }
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }

                var msg = "";
                model.Password = CommonHelper.Encrypt(model.Password);
                var result = _factory.CreateOrUpdate(model, ref msg);
                if (result)
                {
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          path = Server.MapPath("~/Uploads/Employees/" + model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);

                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                    }
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("FirstName", msg);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Create", model));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Create", model));
            }
        }
Пример #5
0
        public ActionResult LoadKeywords()
        {
            CMS_EmployeeModels model = new CMS_EmployeeModels();

            model.ListKeywords = _facKeyword.GetList();
            if (model.ListKeywords != null && model.ListKeywords.Any())
            {
                int index = 0;
                model.ListKeywords.ForEach(o => {
                    o.OffSet = index++;
                });
            }
            return(PartialView("_TableChooseKeywords", model));
        }
Пример #6
0
        public CMS_EmployeeModels GetDetail(string Id)
        {
            NSLog.Logger.Info("EmployeeGetDetail", Id);
            CMS_EmployeeModels result = null;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var data = cxt.CMS_Employee.Where(o => o.ID == Id && o.Status != (byte)Commons.EStatus.Deleted)
                               .Select(o => new CMS_EmployeeModels
                    {
                        Id            = o.ID,
                        Name          = o.Name,
                        RoleID        = o.RoleID,
                        Email         = o.Email,
                        Password      = o.Password,
                        IsActive      = o.IsActive ?? true,
                        Phone         = o.Phone,
                        PinCode       = o.PinCode,
                        Gender        = o.Gender,
                        Marital       = o.Marital,
                        HiredDate     = o.HiredDate,
                        BirthDate     = o.BirthDate,
                        Street        = o.Street,
                        City          = o.City,
                        Country       = o.Country,
                        ZipCode       = o.ZipCode,
                        ImageURL      = string.IsNullOrEmpty(o.ImageUrl) ? "" : o.ImageUrl,
                        StoreID       = o.StoreID,
                        IsSupperAdmin = o.IsSupperAdmin,
                        Quote         = o.Quote,
                    }).FirstOrDefault();

                    result = data;

                    NSLog.Logger.Info("ResponseEmployeeGetDetail", result);
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ErrorEmployeeGetDetail", ex);
            }
            return(result);
        }
Пример #7
0
        public ActionResult AddKeywords(KeyOnGroupModels data)
        {
            CMS_EmployeeModels model = new CMS_EmployeeModels();

            if (data.ListKeywordOnGroup != null && data.ListKeywordOnGroup.Count() > 0)
            {
                model.ListKeywords = new List <CMS_KeywordModels>();
            }

            for (int i = 0; i < data.ListKeywordOnGroup.Count(); i++)
            {
                CMS_KeywordModels key = new CMS_KeywordModels();
                key.OffSet    = data.CurrentOffset;
                key.Id        = data.ListKeywordOnGroup[i].KeyID;
                key.KeySearch = data.ListKeywordOnGroup[i].KeyName;
                key.Sequence  = data.ListKeywordOnGroup[i].Seq;
                model.ListKeywords.Add(key);
                data.CurrentOffset++;
            }

            return(PartialView("_TabKeywords", model));
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }