Ejemplo n.º 1
0
        public UserController(IUnitOfWork unitOfWork, IUserService userService, IRoleService roleService)
        {
            this._unitOfWork = unitOfWork;
            this._userService = userService;
            this._roleService = roleService;

            if (_logoModel == null)
                _logoModel = new LogoModel();
        }
Ejemplo n.º 2
0
        //upload file : auto save avatar
        public ActionResult SaveLogoUpload(HttpPostedFileBase file)
        {
            if (file != null)
            {
                if (_logoModel != null)
                {
                    DeleteTempFile(_logoModel.FileName);
                    _logoModel = null;
                }

                // Upload file in to UploadFolder
                var fileName = ImageUtility.RandomString() + Path.GetFileName(file.FileName);
                var pathFile = Globals.TempImagePath(fileName);
                var physhicalPath = Path.Combine(Server.MapPath(pathFile));
                file.SaveAs(physhicalPath);

                _logoModel = new LogoModel() { FileName = fileName, PictureUrl = pathFile };
                file.SaveAs(physhicalPath);

            }
            return Json(_logoModel, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 3
0
 public ActionResult RemoveLogoUpload()
 {
     DeleteTempFile(_logoModel.FileName);
     _logoModel = null;
     return Json("");
 }
Ejemplo n.º 4
0
        public ActionResult Edit(UserModel model)
        {
            try
            {
                var entity = _userService.Find(model.UserId);
                if (entity != null)
                {
                    //var _userUpdate = userModel.ToEntity();
                    entity.ModifiedDate = DateTime.Now;

                    if (entity.FullName != model.FullName)
                        entity.FullName = model.FullName;

                    if (entity.Email != model.Email)
                        entity.Email = model.Email;

                    if (entity.Phone != model.Phone)
                        entity.Phone = model.Phone;

                    if (entity.Mobile != model.Mobile)
                        entity.Mobile = model.Mobile;

                    if (entity.RoleId != model.RoleId)
                        entity.RoleId = model.RoleId;

                    #region upload image

                    if (_logoModel != null && !string.IsNullOrEmpty(_logoModel.FileName))
                    {
                        //delete file old
                        if (entity.Image != "default.jpg")
                        {
                            var pathOld = Globals.ImagePath(entity.Image);
                            IOUtility.DeleteFile(pathOld);
                        }

                        entity.Image = _logoModel.FileName;
                        var srcFile = Path.Combine(Server.MapPath(Globals.TempImagePath(_logoModel.FileName)));
                        var desFile = Path.Combine(Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName)));

                        // delete image if exist
                        IOUtility.DeleteFile(desFile);

                        // get temp file
                        string tempFile = Server.MapPath(Globals.TempImagePath(_logoModel.FileName));

                        // get folder thumbs
                        string thumbFolder = Server.MapPath(Globals.ThumbPath(ConstantKeys.AvatarFolder, _logoModel.FileName));

                        // get folder image
                        string imageFolder = Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName));

                        // create thumb image
                        System.Drawing.Image img = ImageUtility.ScaleImage(tempFile, 208, 180, "#ffffff");
                        ImageUtility.SaveImage(thumbFolder, img);
                        img.Dispose();

                        // create image
                        img = ImageUtility.ScaleImage(tempFile, 200, 200, "#ffffff");
                        ImageUtility.SaveImage(imageFolder, img);
                        img.Dispose();

                        // delete temp file
                        IOUtility.DeleteFile(srcFile);

                        //// move full images
                        //IOUtility.MoveFile(srcFile, desFile);
                    }
                    _logoModel = null;

                    #endregion

                    entity.ObjectState = ObjectState.Modified;
                    entity.Active = model.Active;

                    _userService.Update(entity);
                    _unitOfWork.SaveChanges();

                    // TODO: Add update logic here
                }
                //return RedirectToAction("Index");
                return Json(new { Status = 1, Message = "Update success." });
            }
            catch
            {
                return Json(new { Status = 0, Message = "Update error." });
            }
        }
Ejemplo n.º 5
0
        public ActionResult Create(UserModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add insert logic here
                    var roleID = model.RoleId;
                    string encryptPassword = "";
                    string passwordSalt = "";
                    passwordSalt = EncryptProvider.GenerateSalt();
                    encryptPassword = EncryptProvider.EncryptPassword(model.Password, passwordSalt);

                    model.CreatedDate = DateTime.Now;
                    model.ModifiedDate = DateTime.Now;
                    model.LastLogonDate = DateTime.Now;

                    model.PasswordSalt = passwordSalt;
                    model.Password = encryptPassword;
                    model.IsAdmin = true;

                    #region upload file image to server

                    try
                    {
                        if (_logoModel != null && !string.IsNullOrEmpty(_logoModel.FileName))
                        {
                            model.Image = _logoModel.FileName;
                            var srcFile = Path.Combine(Server.MapPath(Globals.TempImagePath(_logoModel.FileName)));
                            var desFile = Path.Combine(Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName)));

                            // delete image if exist
                            IOUtility.DeleteFile(desFile);

                            // get temp file
                            string tempFile = Server.MapPath(Globals.TempImagePath(_logoModel.FileName));

                            // get folder thumbs
                            string thumbFolder = Server.MapPath(Globals.ThumbPath(ConstantKeys.AvatarFolder, _logoModel.FileName));

                            // get folder image
                            string imageFolder = Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName));

                            // create thumb image
                            System.Drawing.Image img = ImageUtility.ScaleImage(tempFile, 208, 180, "#ffffff");
                            ImageUtility.SaveImage(thumbFolder, img);
                            img.Dispose();

                            // create image
                            img = ImageUtility.ScaleImage(tempFile, 200, 200, "#ffffff");
                            ImageUtility.SaveImage(imageFolder, img);
                            img.Dispose();

                            // delete temp file
                            IOUtility.DeleteFile(srcFile);

                            //// move full images
                            //IOUtility.MoveFile(srcFile, desFile);
                        }
                        else
                            model.Image = "default.jpg";
                        _logoModel = null;
                    }
                    catch (Exception ex)
                    {
                        model.Image = "default.jpg";
                        ex.ToString();
                    }

                    #endregion

                    var _userEntity = model.ToEntity();

                    _userEntity.ObjectState = ObjectState.Added;
                    _userService.Insert(_userEntity);
                    _unitOfWork.SaveChanges();

                    return RedirectToAction("Index");
                }
                return View(model);
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 6
0
        public ActionResult Create(ProductModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CreatedDate = DateTime.Now;
                    model.UpdatedDate = DateTime.Now;
                    model.CreatedBy = User.Identity.Name;
                    model.UpdatedBy = User.Identity.Name;
                    model.IsActive = true;
                    model.Alias = Globals.GenerateAlias(model.Name, true);

                    #region upload file image to server

                    try
                    {
                        if (_logoModel != null && !string.IsNullOrEmpty(_logoModel.FileName))
                        {
                            model.Picture = _logoModel.FileName;
                            var srcFile = Path.Combine(Server.MapPath(Globals.TempImagePath(_logoModel.FileName)));
                            var desFile = Path.Combine(Server.MapPath(Globals.ImagePath(ConstantKeys.ProductFolder, _logoModel.FileName)));

                            // delete image if exist
                            IOUtility.DeleteFile(desFile);

                            // get temp file
                            string tempFile = Server.MapPath(Globals.TempImagePath(_logoModel.FileName));

                            // get folder thumbs
                            string thumbFolder = Server.MapPath(Globals.ThumbPath(ConstantKeys.ProductFolder, _logoModel.FileName));

                            // get folder image
                            string imageFolder = Server.MapPath(Globals.ImagePath(ConstantKeys.ProductFolder, _logoModel.FileName));

                            // create thumb image
                            System.Drawing.Image img = ImageUtility.ScaleImage(tempFile, 208, 180, "#ffffff");
                            ImageUtility.SaveImage(thumbFolder, img);
                            img.Dispose();

                            // create image
                            img = ImageUtility.ScaleImage(tempFile, 200, 200, "#ffffff");
                            ImageUtility.SaveImage(imageFolder, img);
                            img.Dispose();

                            // delete temp file
                            IOUtility.DeleteFile(srcFile);

                            //// move full images
                            //IOUtility.MoveFile(srcFile, desFile);
                        }
                        else
                            model.Picture = "default.jpg";
                        _logoModel = null;
                    }
                    catch (Exception ex)
                    {
                        model.Picture = "default.jpg";
                        ex.ToString();
                    }

                    #endregion

                    var entity = model.ToEntity();
                    entity.ObjectState = ObjectState.Added;
                    _productService.Insert(entity);
                    _unitOfWork.SaveChanges();

                    return RedirectToAction("Index");
                }
                else
                {
                    return View(model);
                }
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 7
0
        public string Edit(ProductModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = _productService.Find(model.Id);
                if (entity != null)
                {
                    entity.UpdatedDate = DateTime.Now;
                    if (entity.Name != model.Name)
                    {
                        entity.Name = model.Name;
                        entity.Alias = Globals.GenerateAlias(model.Name, true);
                    }
                    if (entity.Brief != model.Description)
                        entity.Brief = model.Description;
                    if (entity.Description != model.Content)
                        entity.Description = model.Content;
                    if (entity.CategoryId != model.CategoryId)
                        entity.CategoryId = model.CategoryId;
                    if (entity.Price != model.Price)
                        entity.Price = model.Price;
                    if (entity.Unit != model.Unit)
                        entity.Unit = model.Unit;
                    if (entity.IsActive != model.IsActive)
                        entity.IsActive = model.IsActive;
                    //if (entity.IsFeature != model.ShowIndex)
                    //    entity.IsFeature = model.ShowIndex;
                    if (entity.Origin != model.Origin)
                        entity.Origin = model.Origin;
                    if (entity.CallPrice != model.CallPrice)
                        entity.CallPrice = model.CallPrice;

                    #region upload image

                    if (_logoModel != null && !string.IsNullOrEmpty(_logoModel.FileName))
                    {
                        //delete file old
                        if (entity.Thumbnail != "default.jpg")
                        {
                            var pathOld = Globals.ImagePath(entity.Thumbnail);
                            IOUtility.DeleteFile(pathOld);
                        }

                        entity.Thumbnail = _logoModel.FileName;
                        var srcFile = Path.Combine(Server.MapPath(Globals.TempImagePath(_logoModel.FileName)));
                        var desFile = Path.Combine(Server.MapPath(Globals.ImagePath(ConstantKeys.ProductFolder, _logoModel.FileName)));

                        // delete image if exist
                        IOUtility.DeleteFile(desFile);

                        // get temp file
                        string tempFile = Server.MapPath(Globals.TempImagePath(_logoModel.FileName));

                        // get folder thumbs
                        string thumbFolder = Server.MapPath(Globals.ThumbPath(ConstantKeys.ProductFolder, _logoModel.FileName));

                        // get folder image
                        string imageFolder = Server.MapPath(Globals.ImagePath(ConstantKeys.ProductFolder, _logoModel.FileName));

                        // create thumb image
                        System.Drawing.Image img = ImageUtility.ScaleImage(tempFile, 208, 180, "#ffffff");
                        ImageUtility.SaveImage(thumbFolder, img);
                        img.Dispose();

                        // create image
                        img = ImageUtility.ScaleImage(tempFile, 200, 200, "#ffffff");
                        ImageUtility.SaveImage(imageFolder, img);
                        img.Dispose();

                        // delete temp file
                        IOUtility.DeleteFile(srcFile);

                        //// move full images
                        //IOUtility.MoveFile(srcFile, desFile);
                    }
                    _logoModel = null;

                    #endregion

                    entity.ObjectState = ObjectState.Modified;
                    _productService.Update(entity);
                    _unitOfWork.SaveChanges();
                }
                return JsonConvert.SerializeObject(new { Status = 1, Message = "Update success." });
            }
            else
            {
                return JsonConvert.SerializeObject(new { Status = 0, Message = "Update unsuccess." });
            }
        }