public ActionResult Edit(CreateProductHistoryViewModel model) { var productHistoryToUpdate = new ProductHistory(); ProductHistory newProductHistory = new ProductHistory() { ProductID = model.ProductID, HistoryID = model.HistoryID, Comment = model.Comment, Date = model.DateTimeNow, UserID = model.Email }; var product = _unityOfWork.Product.getProductWithHistory(model.ProductID); long id = product.ID; // find history entry in list of histories foreach (var productHistory in product.ProductHistories) { // a unique history entry is given by ProductID, HistoryID, Date if (productHistory.Date.ToString() == model.DateTimeNow.ToString() && model.OldHistoryID == productHistory.HistoryID && model.Email == productHistory.UserID) { productHistoryToUpdate = productHistory; break; } } product.ProductHistories.Remove(productHistoryToUpdate); product.ProductHistories.Add(newProductHistory); _unityOfWork.Product.Update(product); _unityOfWork.Save(); newProductHistory.User = null; newProductHistory.UserID = null; LoggingController.writeLog(newProductHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Details", new { id = id })); }
public ActionResult Delete(int productId, string userId, DateTime date, int historyId) { var productHistoryToDelete = new ProductHistory(); var product = _unityOfWork.Product.getProductWithHistory(productId); int id = productId; foreach (var productHistory in product.ProductHistories) { if (date.ToString() == productHistory.Date.ToString() && historyId == productHistory.HistoryID && userId == productHistory.UserID) { productHistoryToDelete = productHistory; break; } } product.ProductHistories.Remove(productHistoryToDelete); _unityOfWork.Product.Update(product); _unityOfWork.Save(); productHistoryToDelete.User = null; productHistoryToDelete.UserID = null; LoggingController.writeLog(productHistoryToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Details", new { id = id })); }