示例#1
0
        public ActionResult Edit(EditUserBm bind)
        {
            if (this.ModelState.IsValid)
            {
                HttpPostedFileBase file = this.Request.Files["salePicture"];

                if (file == null || !file.ContentType.Contains("image"))
                {
                    this.ModelState.AddModelError("profilePicture", "Invalid image");
                }
                else
                {
                    var    pathToFolder = this.Server.MapPath("~/ProfilePictures");
                    string fileName     = Path.GetFileName(file.FileName);
                    string path         = this.service.GetAdequatePathToSave(pathToFolder, fileName);
                    file.SaveAs(path);

                    var imageUrl = this.service.GetImageUrl(path);
                    bind.ProfilePictureUrl = imageUrl;

                    string currentUsername = this.User.Identity.Name;
                    this.service.EditUser(bind, currentUsername);

                    return(this.RedirectToAction("Profile"));
                }
            }

            string     username = this.User.Identity.Name;
            EditUserVm vm       = this.service.GetEditVm(username);

            return(this.View(vm));
        }
示例#2
0
        public void EditUserFromBm(string currentUserName, EditUserBm model)
        {
            var currentUser = this.Context.Users.FirstOrDefault(x => x.UserName == currentUserName);

            currentUser.Name  = model.Name;
            currentUser.Email = model.Email;
            this.Context.SaveChanges();
        }
示例#3
0
        public void EditUser(EditUserBm bind, string currentName)
        {
            ApplicationUser user =
                this.Context.Users.FirstOrDefault(applicationUser => applicationUser.UserName == currentName);

            user.Name  = bind.Name;
            user.Email = bind.Email;
            this.Context.SaveChanges();
        }
        public void EditUser(EditUserBm bind, User user)
        {
            User currentUser = this.Context.Users.Find(user.Id);

            currentUser.Email    = bind.Email;
            currentUser.Password = bind.Password;
            currentUser.Phone    = bind.Phone;
            this.Context.SaveChanges();
        }
示例#5
0
        public ActionResult Edit(EditUserBm bind)
        {
            if (this.ModelState.IsValid)
            {
                string currentName = this.User.Identity.Name;
                this.service.EditUser(bind, currentName);
                return(this.RedirectToAction("Profile"));
            }

            string     userName = this.User.Identity.Name;
            EditUserVm vm       = this.service.GetEditVm(userName);

            return(this.View(vm));
        }
        public void Edit(EditUserBm bind, byte[] imageBytes)
        {
            var entity = this.users
                         .All()
                         .FirstOrDefault(u => u.Id == bind.Id);

            if (imageBytes != null)
            {
                entity.UserPhoto = imageBytes;
            }

            this.users.Update(entity);
            this.users.SaveChanges();
        }
        public ActionResult Edit(EditUserBm model)
        {
            if (this.ModelState.IsValid)
            {
                string currentUserName = this.User.Identity.Name;
                this.service.EditUserFromBm(currentUserName, model);
                return(this.RedirectToAction("Profile"));
            }

            string userName  = this.User.Identity.Name;
            var    viewModel = this.service.GetEditUserVm(userName);

            return(this.View(viewModel));
        }
        public bool EditUserPersonalDetails(EditUserBm bm, string appUserId)
        {
            var model = Mapper.Map <EditUserBm, UserProfileBm>(bm);

            //var oldImgUrl = this.userService.GetUserImgUrl(appUserId);

            if (this.CanUploadImage(bm.Image))
            {
                var newImgUrl = this.GetDownloadbleLink(bm.Image, bm.ServerPath);

                model.ImageUrl = newImgUrl;
            }

            var result = this.AddUserDetails(model, appUserId);

            return(result);
        }
        public ActionResult EditProfile(EditUserBm bind)
        {
            string sessionId = this.Request.Cookies.Get("sessionId")?.Value;

            if (!AuthenticationManager.IsAuthenticated(sessionId))
            {
                return(this.RedirectToAction("Login", "Users"));
            }

            User user = AuthenticationManager.GetAuthenticatedUser(sessionId);

            if (this.ModelState.IsValid && bind.CurrentPassword == user.Password)
            {
                this.service.EditUser(bind, user);
                return(this.RedirectToAction("Profile"));
            }

            EditUserVm vm = this.service.GetEditUserVm(user);

            return(this.View(vm));
        }
        public ActionResult Edit(EditUserBm bm)
        {
            if (!this.ModelState.IsValid)
            {
                //error page

                //var errorModel = new EditUserVm();

                //foreach (var kvp in this.ModelState)
                //{
                //    if (kvp.Value.Errors.Count > 0)
                //    {
                //        var errorMsg =
                //            this.langManager.GetLanguageValueByKey(kvp.Value.Errors.FirstOrDefault().ErrorMessage,
                //                this.langManager.GetCurrentLang(this.HttpContext).TwoLetterCode);
                //        errorModel.Errors.Add(kvp.Key, errorMsg);
                //    }
                //}

                //this.TempData["errorModel"] = errorModel;

                //return this.RedirectToAction("Edit");

                this.Response.StatusCode = 400;
                return(this.View("_Custom400BadRequestError"));
            }

            bm.ServerPath = this.Server.MapPath(CRRConfig.CarRepaitReportJson);

            var result = this.myUserManager.EditUserPersonalDetails(bm, this.User.Identity.GetUserId());

            if (!result)
            {
                this.Response.StatusCode = 500;
                return(this.View("_Custom500InternalServerError"));
            }

            return(this.RedirectToAction("UserProfile"));
        }
示例#11
0
        public ActionResult Edit([Bind(Exclude = "UserPhoto")] EditUserBm bind)
        {
            if (this.ModelState.IsValid)
            {
                byte[] imageData = null;
                if (this.Request.Files.Count > 0)
                {
                    HttpPostedFileBase httpPostedFileBase = this.Request.Files["UserPhoto"];

                    using (var binary = new BinaryReader(httpPostedFileBase.InputStream))
                    {
                        imageData = binary.ReadBytes(httpPostedFileBase.ContentLength);
                    }
                }

                this.userService.Edit(bind, imageData);
                return(this.RedirectToAction("ProfilePage"));
            }

            var editUserVm = this.userService.GetEditVm(bind.Id);

            return(this.View(editUserVm));
        }