public ActionResult UpdateProfilePicture(int id, int?seminarId, int?x, int?y, int?height, int?width, bool admin = false) { var person = _personRepository.GetNullableById(id); if (person == null) { Message = string.Format(Messages.NotFound, "Person", id); return(this.RedirectToAction(a => a.SiteList())); } // ensure that a crop has been specified if (!x.HasValue || !y.HasValue || !height.HasValue || !width.HasValue) { Message = "Please specify a crop of the picture by clicking and dragging the box over the crop you would like."; return(View(person)); } // validate this is the person or is a person in user role if (person.User.LoweredUserName != CurrentUser.Identity.Name.ToLower() && !Roles.IsUserInRole(RoleNames.User)) { return(this.RedirectToAction <ErrorController>(a => a.NotAuthorized())); } // crop the image var cropped = _pictureService.Crop(person.OriginalPicture, x.Value, y.Value, width.Value, height.Value); // get the main profile picture person.MainProfilePicture = _pictureService.MakeMainProfile(cropped); // get the thumbnail person.ThumbnailPicture = _pictureService.MakeThumbnail(cropped); person.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { Message = string.Format(Messages.Saved, "Person"); _personRepository.EnsurePersistent(person); _eventService.PhotoUpdate(person, Site); if (seminarId.HasValue) { return(this.RedirectToAction(a => a.AdminEdit(person.User.Id, seminarId.Value, null))); } if (_userRepository.Queryable.Any(a => a.LoweredUserName == CurrentUser.Identity.Name.ToLower())) { return(this.RedirectToAction(a => a.Edit(null))); } return(this.RedirectToAction(a => a.SiteList())); } // set this to check for admin routing back to attendee edit page ViewBag.SeminarId = seminarId; ViewBag.Admin = admin; return(View(person)); }