public ActionResult ChangeAvatar(string id, string left, string top, string right, string bottom, string src) { try { if (User.Identity.IsAuthenticated && ((User.IsInRole("Administrator") && (id == User.Identity.GetUserId())) || User.IsInRole("Admin"))) { int left_int = Convert.ToInt32(left.Split(new char[] { '.' })[0]); int top_int = Convert.ToInt32(top.Split(new char[] { '.' })[0]); int right_int = Convert.ToInt32(right.Split(new char[] { '.' })[0]); int bottom_int = Convert.ToInt32(bottom.Split(new char[] { '.' })[0]); string expansion = src.Split(new char[] { '.' }).Last(); string fileName = Guid.NewGuid().ToString() + '.' + expansion; if (right_int > left_int && bottom_int > top_int) { if ((right_int - left_int) > (bottom_int - top_int)) { right_int--; } if ((right_int - left_int) < (bottom_int - top_int)) { bottom_int--; } if ((right_int - left_int) != (bottom_int - top_int)) { throw new Exception(); } CustomImage.Crop(Image.FromFile(Server.MapPath("~" + src)), new Rectangle(left_int, top_int, right_int - left_int, bottom_int - top_int), fileName, Server); KindergartenManager.AddPreviewPicture(id, fileName, Server); } else { throw new Exception(); } return(RedirectToAction("KindergartenProfile", "Kindergarten", id)); } } catch (Exception) { } return(RedirectToAction("Index", "Home")); }