public bool Save(CommonModelHelper model) { bool isSuccessful = true; try { var culturalItems = new List <string> { "ActionDetails" }; ModelBinder.SetCulturalValue(model.EstimationAction, model, culturalItems); model.EstimationAction.OperationDate = DateTime.Now; model.EstimationAction.Estimation = _dbContext.Estimations.Find(model.EstimationAction.EstimationID); if (model.EstimationAction.ID == Guid.Empty) { model.EstimationAction.ID = Guid.NewGuid(); _dbContext.EstimationActions.Add(model.EstimationAction); } else { _dbContext.Entry(model.EstimationAction).State = EntityState.Modified; } _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "EstimationAction", message); throw new Exception(message); } return(isSuccessful); }
public bool Save(CommonModelHelper model) { var isSuccess = true; try { var culturalItems = new List <string> { "CoordinatorPrecautions", "CoordinatorNotes", "NotesToStaff", "ComplainDetails", "AccountingRelatedMemo" }; ModelBinder.SetCulturalValue(model.Order, model, culturalItems); model.Order.ApplicationID = model.ApplicationID; model.Order.OrderStatus = (int)OrderStatus.Ordered; //Save Order if (model.Order.ID == Guid.Empty) { model.Order.ID = Guid.NewGuid(); model.Order.InvoiceNo = GenerateInvoiceNo(); model.Order.Estimation = _dbContext.Estimations.Find(model.Estimation.ID); model.Order.OrderNo = GenerateOrderNo(); model.Order.CompanyID = model.Estimation.ClientID; model.Order.Company = _dbContext.Companies.Find(model.Order.CompanyID); _dbContext.Orders.Add(model.Order); } else { _dbContext.Entry(model.Order).State = EntityState.Modified; } //Save or update Order details foreach (var item in model.OrderDetails) { item.OrderID = model.Order.ID; item.Order = model.Order; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.OrderDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } } //Update Estimation //_dbContext.Entry(model.Estimation).State = EntityState.Modified; _dbContext.SaveChanges(); } catch (Exception ex) { isSuccess = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "OrderDetails", message); throw new Exception(message); } return(isSuccess); }
public bool Save(CommonModelHelper model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.OverheadCost; model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details model.EstimationDetails.ForEach(item => { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.EstimationDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } }); _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "OverheadCostQuotation", message); throw new Exception(message); } return(isSuccessful); }
public bool SaveTranscriptionEstimation(CommonModelHelper_Transcription model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks", "CoordinatorNotes", "QuotationNotes" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.Transcription; if (model.Estimation.EstimationStatus == 0) { model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; } ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { //model.Estimation.FirstDeliveryDate = null; //model.Estimation.FinalDeliveryDate = null; _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details foreach (var item in model.EstimationDetails) { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if ((item.ID == Guid.Empty) && (!item.IsMarkedForDelete)) { item.ID = Guid.NewGuid(); var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item); _dbContext.EstimationDetails.Add(mapItem); } else { if ((!item.IsMarkedForDelete) && (item.ID != Guid.Empty)) { var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item); _dbContext.Entry(mapItem).State = EntityState.Modified; } if ((item.IsMarkedForDelete) && (item.ID != Guid.Empty)) { var itm = _dbContext.EstimationDetails.Find(item.ID); _dbContext.EstimationDetails.Remove(itm); } } } #region "Commented" ////Save file type //var existingFileTypes = _dbContext.EstimationDeliveryFileTypes.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); //var existingWorkContent = _dbContext.EstimationWorkContents.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); //existingFileTypes?.ForEach(eft => //{ // _dbContext.EstimationDeliveryFileTypes.Remove(eft); //}); //existingWorkContent?.ForEach(ewc => //{ // _dbContext.EstimationWorkContents.Remove(ewc); //}); //model.FileTypes?.ForEach(ft => //{ // var fileType = new EstimationDeliveryFileType // { // ID = Guid.NewGuid(), // Estimation = model.Estimation, // FileType = ft.FileType, // Version = ft.Version, // IsDeleted = false // }; // _dbContext.EstimationDeliveryFileTypes.Add(fileType); //}); ////Save work content //model.WorkContents?.ForEach(wc => //{ // var content = new EstimationWorkContent // { // ID = Guid.NewGuid(), // Estimation = model.Estimation, // WorkContent = wc.WorkContent, // IsDeleted = false // }; // _dbContext.EstimationWorkContents.Add(content); //}); #endregion "Commented" _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "TranscriptionEstimation", message); throw new Exception(message); } return(isSuccessful); }
public bool Save(CommonModelHelper model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.Narration; model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details foreach (var item in model.EstimationDetails) { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.EstimationDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } } //Save file type var existingWorkContent = _dbContext.EstimationWorkContents.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); existingWorkContent?.ForEach(ewc => { _dbContext.EstimationWorkContents.Remove(ewc); }); //Save work content model.WorkContents?.ForEach(wc => { var content = new EstimationWorkContent { ID = Guid.NewGuid(), Estimation = model.Estimation, WorkContent = wc.WorkContent, IsDeleted = false }; _dbContext.EstimationWorkContents.Add(content); }); model.estimationCompetencies?.ForEach(ec => { var content = new EstimationCompetency { ID = Guid.NewGuid(), Estimation = model.Estimation, CompetencyType = ec.CompetencyType, CompetencyDetail = ec.CompetencyDetail }; _dbContext.EstimationCompetencies.Add(content); }); if (model.EstimationNarrationExpense.ID == Guid.Empty) { model.EstimationNarrationExpense.ID = Guid.NewGuid(); model.EstimationNarrationExpense.EstimationID = model.Estimation.ID; _dbContext.EstimationNarrationExpenses.Add(model.EstimationNarrationExpense); } else { _dbContext.Entry(model.EstimationNarrationExpense).State = EntityState.Modified; } _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "NarrationEstimation", message); throw new Exception(message); } return(isSuccessful); }