public void Delete(TruckExpenseModel truckExpenseModel) { try { if (ValidateDelete(truckExpenseModel)) { return; } Common.DAL.TruckExpens truckExpens = dbContext.TruckExpenses.Where(x => x.Id == truckExpenseModel.Id).FirstOrDefault(); if (truckExpens == null) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound); return; } dbContext.TruckExpenses.Remove(truckExpens); base.SaveChanges(); truckExpenseModel.AddSuccess(Resources.TruckExpenseDeletedSuccessfully, LookUps.SuccessType.Full); } catch (System.Data.Entity.Infrastructure.DbUpdateException) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Business, null, Resources.RefrenceDeleteError); base.UndoUpdates(); } catch (Exception ex) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }
public void Edit(TruckExpenseModel truckExpenseModel) { try { Common.DAL.TruckExpens truckExpens = dbContext.TruckExpenses.Where(x => x.Id == truckExpenseModel.Id).FirstOrDefault(); if (truckExpens == null) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound); return; } if (Validate(truckExpenseModel)) { return; } TruckExpenseMapper.Map(dbContext, truckExpenseModel, truckExpens); base.SaveChanges(); truckExpenseModel.AddSuccess(Resources.TruckExpenseUpdatedSuccessfully, LookUps.SuccessType.Full); } catch (Exception ex) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }
public ActionResult Create(BaseModel baseModel) { TruckExpenseModel truckExpenseModel = new TruckExpenseModel(); truckExpenseModel.CopyBaseModel(baseModel); using (TruckExpenseBAL truckExpenseBAL = new TruckExpenseBAL(ContextInfo)) { truckExpenseBAL.PrepareTruckExpenseModel(truckExpenseModel); } return(View("Create", truckExpenseModel)); }
public ActionResult Delete(string id) { TruckExpenseModel truckExpenseModel = new TruckExpenseModel(); truckExpenseModel.Id = id; using (TruckExpenseBAL truckExpenseBAL = new TruckExpenseBAL(ContextInfo)) { truckExpenseBAL.GetTruckExpenseModel(truckExpenseModel); } return(View(truckExpenseModel)); }
public ActionResult Delete(TruckExpenseModel truckExpenseModel) { using (TruckExpenseBAL truckExpenseBAL = new TruckExpenseBAL(ContextInfo)) { truckExpenseBAL.Delete(truckExpenseModel); if (truckExpenseModel.HasErrorByType()) { truckExpenseBAL.GetTruckExpenseModel(truckExpenseModel); } } return(View(truckExpenseModel)); }
public static void Map(LMYFrameWorkMVCEntities dbContext, List <TruckExpens> src, List <TruckExpenseModel> dest) { if (src == null || dest == null) { return; } foreach (TruckExpens truckExpens in src) { TruckExpenseModel truckExpenseModel = new TruckExpenseModel(); Map(dbContext, truckExpens, truckExpenseModel); dest.Add(truckExpenseModel); } }
public static void Map(LMYFrameWorkMVCEntities dbContext, TruckExpenseModel src, TruckExpens dest) { if (src == null || dest == null) { return; } dest.CopyPropertyValues(src); if (!string.IsNullOrEmpty(src.AtDateString)) { dest.AtDate = src.AtDateString.ConvertToDateTime(); } }
// GET: TruckExpense/Edit/5 public ActionResult Edit(string id, BaseModel baseModel) { TruckExpenseModel truckExpenseModel = new TruckExpenseModel(); truckExpenseModel.CopyBaseModel(baseModel); truckExpenseModel.Id = id; using (TruckExpenseBAL truckExpenseBAL = new TruckExpenseBAL(ContextInfo)) { truckExpenseBAL.GetTruckExpenseModel(truckExpenseModel); truckExpenseBAL.PrepareTruckExpenseModel(truckExpenseModel); } return(View(truckExpenseModel)); }
public void PrepareTruckExpenseModel(TruckExpenseModel truckExpenseModel) { try { truckExpenseModel.TruckExpensesTypesList = dbContext.TruckExpensTypes. Select(x => new { x.Id, x.Name, }).ToList().OrderBy(x => x.Name).Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); } catch (Exception ex) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Critical, ex); } }
public void GetTruckExpenseModel(TruckExpenseModel truckExpenseModel) { try { Common.DAL.TruckExpens truckExpens = dbContext.TruckExpenses.Where(x => x.Id == truckExpenseModel.Id).FirstOrDefault(); if (truckExpens == null) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound); } else { TruckExpenseMapper.Map(dbContext, truckExpens, truckExpenseModel); } } catch (Exception ex) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Critical, ex); } }
public static void Map(LMYFrameWorkMVCEntities dbContext, TruckExpens src, TruckExpenseModel dest) { if (src == null || dest == null) { return; } dest.CopyPropertyValues(src); dest.AtDateString = src.AtDate.ToStringDateFormat(); if (src.TruckExpensType != null) { dest.ExpenseTypeModel.CopyPropertyValues(src.TruckExpensType); } if (src.Truck != null) { dest.TruckModel.CopyPropertyValues(src.Truck); } }
public void Create(TruckExpenseModel truckExpenseModel) { try { if (Validate(truckExpenseModel)) { return; } using (var transaction = dbContext.Database.BeginTransaction()) { try { Common.DAL.TruckExpens truckExpens = new Common.DAL.TruckExpens(); TruckExpenseMapper.Map(dbContext, truckExpenseModel, truckExpens); truckExpens.Id = Guid.NewGuid().ToString(); dbContext.TruckExpenses.Add(truckExpens); base.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } truckExpenseModel.AddSuccess(Resources.TruckExpenseAddedSuccessfully, LookUps.SuccessType.Full); } } catch (Exception ex) { base.HandleError(truckExpenseModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }
public ActionResult Create(TruckExpenseModel truckExpenseModel) { ModelState.Clear <TruckExpenseModel>(x => x.TruckModel); using (TruckExpenseBAL truckExpenseBAL = new TruckExpenseBAL(ContextInfo)) { if (ModelState.IsValid) { truckExpenseBAL.Create(truckExpenseModel); } if (truckExpenseModel.HasErrorByType(LMYFrameWorkMVC.Common.LookUps.ErrorType.Critical) || truckExpenseModel.HasSuccess(LMYFrameWorkMVC.Common.LookUps.SuccessType.Full)) { return(base.RedirectToActionWithData(new Dictionary <string, object> { { "baseModel", truckExpenseModel } })); } truckExpenseBAL.PrepareTruckExpenseModel(truckExpenseModel); } return(View("Create", truckExpenseModel)); }
private bool ValidateDelete(TruckExpenseModel truckExpenseModel) { return(truckExpenseModel.HasErrorByType()); }