public ActionResult CreateSheet(EstimateModel estimate) { var newEstimate = new Estimate { Title = estimate.Title, Comments = estimate.Comments, CreatedByUserId = WebUser.Id }; _estimateRepository.Create(newEstimate); _unitOfWork.Commit(); foreach (var lineItem in estimate.Rows) { var newEstimateLineItem = new EstimateLineItem() { EstimateId = newEstimate.Id, Module = lineItem.Module, Task = lineItem.Task, Effort = lineItem.Effort, Comment = lineItem.Comment, WorkType = lineItem.WorkType }; _estimateLineItemRepository.Create(newEstimateLineItem); } _unitOfWork.Commit(); return(Json(true)); }
public ActionResult UpdateSheet(EstimateModel estimate) { var selectedEstimate = _estimateRepository.Get(estimate.Id); if (selectedEstimate != null) { selectedEstimate.Title = estimate.Title; selectedEstimate.Comments = estimate.Comments; selectedEstimate.UpdatedByUserId = WebUser.Id; _estimateRepository.Update(selectedEstimate); _unitOfWork.Commit(); // Remove Existing var existingRows = _estimateLineItemRepository.GetAllBy(t => t.EstimateId == selectedEstimate.Id); foreach (var existingRow in existingRows) { _estimateLineItemRepository.Delete(existingRow); } _unitOfWork.Commit(); // Add Fresh foreach (var lineItem in estimate.Rows) { var newEstimateLineItem = new EstimateLineItem { EstimateId = selectedEstimate.Id, Module = lineItem.Module, Task = lineItem.Task, Effort = lineItem.Effort, Comment = lineItem.Comment, WorkType = lineItem.WorkType }; _estimateLineItemRepository.Create(newEstimateLineItem); } _unitOfWork.Commit(); return(Json(true)); } return(Json(false)); }