public JsonResult CropPicture(int entityID, int uploadID, double x, double y, double width, double height) { try { var upload = uploadRepository.GetById(uploadID); var entity = entityRepository.GetById(entityID); var currentEntity = SessionHelper.CurrentEntity; var citizen = SessionHelper.LoggedCitizen; var crop = new CropRectangle((int)x, (int)y, (int)width, (int)height); var result = uploadAvatarService.CanCropUpload(upload, entity, currentEntity, citizen, crop); if (result.IsError) { return(JsonError(result)); } var newUpload = uploadAvatarService.CropUploadAndMoveToAnotherLocation(upload, crop, UploadLocationEnum.Avatars); entity.ImgUrl = uploadAvatarService.GetRelativePathForLocation(newUpload); uploadRepository.SaveChanges(); return(JsonData(new { msg = "Avatar changed!", img = entity.ImgUrl })); } catch (Exception e) { return(UndefinedJsonError(e)); } }