示例#1
0
        public async Task <IActionResult> EditProfile(UserEditProFileViewModel userEditProFileViewModel, IFormFile UserImage)
        {
            var user = _userService.GetUserById(userEditProFileViewModel.UserID);

            if (user == null)
            {
                ViewBag.error = "اطلاعات را درست وارد کنید";
                return(View("Index", GetUserInfo()));
            }

            if (user.UserName != user.UserName)
            {
                if (_userService.UserNameIsExist(userEditProFileViewModel.UserName))
                {
                    ViewBag.error = "این نام کاربری وجود دارد";
                    return(View("Index", GetUserInfo()));
                }
            }
            if (user.UserEmail != userEditProFileViewModel.UserEmail)
            {
                if (_userService.UserEmialIsExist(userEditProFileViewModel.UserEmail))
                {
                    ViewBag.error = "این  ایمیل وجود دارد";
                    return(View("Index", GetUserInfo()));
                }
            }

            if (userEditProFileViewModel.UserImage != null)
            {
                string imgName = TextTools.GenerateUniqCode() + Path.GetExtension(userEditProFileViewModel.UserImage.FileName);;
                string a       = Directory.GetCurrentDirectory();
                string upLoad  = await ImageUploader.ImageUpload(a, "/wwwroot/PorojectImg/UserImage/", user.UserImage, imgName, userEditProFileViewModel.UserImage);

                if (upLoad != "1")
                {
                    ViewBag.error = "خطا در اپلود تصویر";
                    return(View("Index", GetUserInfo()));
                }
                user.UserImage = imgName;
            }


            #region Update
            user.UserName      = userEditProFileViewModel.UserName;
            user.UserFristName = userEditProFileViewModel.UserFristName;
            user.UserLastName  = userEditProFileViewModel.UserLastName;
            user.UserEmail     = userEditProFileViewModel.UserEmail;
            user.UserAbout     = userEditProFileViewModel.UserAbout;
            user.UserBirthday  = userEditProFileViewModel.UserBirthday;
            _userRepository.UpdateUser(user);
            _userRepository.SaveUser();
            #endregion
            return(View("Index", GetUserInfo()));
        }
        public IActionResult Post([FromForm(Name = ("file"))] IFormFile file, [FromForm] CarImage carImage)
        {
            var check = CheckFormValues(file, carImage);

            if (check != null)
            {
                return(BadRequest(check));
            }

            var imagePath = ImageUploader.ImageUpload(DefaultImagePath, file);

            carImage.ImagePath = imagePath.Result;

            var result = _carImageService.Add(carImage);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }