示例#1
0
        public IActionResult Modify(UserView userView, IFormFile photonew)
        {
            UserView user = UserBus.GetDataById(userView.Id);   //infor user cũ

            string fileOld = user.Photo;

            userView.Photo = fileOld;
            if (photonew != null)
            {
                userView.Photo = FileCuaSang.SaveFile(webHostEnvironment, photonew, "assets/image");
            }
            bool check = UserBus.Modify(userView);

            if (check)
            {
                if (photonew != null)
                {
                    FileCuaSang.RemoveFile(webHostEnvironment, fileOld);
                }
                TempData["Result"] = 200;
                return(RedirectToAction("detail", "user", new
                {
                    area = "admin",
                    id = userView.Id
                }));
            }
            else
            {
                user.Id      = userView.Id;
                user.Name    = userView.Name;
                user.Address = userView.Address;
                user.Phone   = userView.Phone;
                user.Gender  = userView.Gender;
                CookieCuaSang.Set(HttpContext, "user-edit", JsonConvert.SerializeObject(user), null);
                TempData["Result"] = 500;
                return(RedirectToAction("detail", "user", new
                {
                    area = "admin",
                    id = userView.Id
                }));
            }
        }