public ActionResult Create(ImageSubCategory imageSubCategory, IFormCollection collection) { try { // TODO: Add insert logic here var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); imageSubCategory.ImageCategoryId = Convert.ToInt64(collection["CategoryId"]); imageSubCategory.DateCreated = DateTime.Now; imageSubCategory.DateLastModified = DateTime.Now; imageSubCategory.CreatedBy = signedInUserId; imageSubCategory.LastModifiedBy = signedInUserId; _databaseConnection.ImageSubCategories.Add(imageSubCategory); _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully added a new Image Sub-Category!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index", new{ id = imageSubCategory.ImageCategoryId })); } catch { return(View()); } }
public ActionResult Edit(ImageSubCategory imageSubCategory) { try { // TODO: Add update logic here var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); imageSubCategory.DateLastModified = DateTime.Now; imageSubCategory.LastModifiedBy = signedInUserId; _databaseConnection.Entry(imageSubCategory).State = EntityState.Modified; _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully modified the Image Sub-Category!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index", new { id = imageSubCategory.ImageCategoryId })); } catch { return(View()); } }