private void SoftDelete(tblT_Cost cost) { if (cost != null) { cost.Status_FK = (int)RecordStatus.Deleted; } }
private void HardDelete(tblT_Cost cost) { if (cost != null) { Db.tblT_Cost.Remove(cost); } }
public void Update(CostDTO costDTO, DateTime dateStamp) { if (costDTO == null) { throw new ArgumentNullException("Cost model is null."); } tblT_Cost cost = costFactory.CreateFromDbAndUpdateFromDTO(costDTO, dateStamp); }
public tblT_Cost Insert(CostDTO costDTO, DateTime dateStamp) { if (costDTO == null) { throw new ArgumentNullException("Cost model is null."); } tblT_Cost cost = costFactory.CreateFromDTO(costDTO, dateStamp); return(Db.tblT_Cost.Add(cost)); }
public tblT_Cost CreateFromDTO(CostDTO costDTO, DateTime dateStamp) { if (costDTO == null) { throw new ArgumentNullException("Cost model is null."); } costDTO.Status_FK = (int)RecordStatus.Active; costDTO.CreatedBy = User.Username; costDTO.CreatedDate = dateStamp; costDTO.UpdatedBy = User.Username; costDTO.UpdatedDate = dateStamp; tblT_Cost cost = costDTO.ToObject <tblT_Cost>(); return(cost); }
public SaveResult <CostEntryModel> Save(CostDTO costDTO, DateTime dateStamp) { ModelValidationResult validationResult = costValidator.Validate(costDTO); bool success = false; CostEntryModel model = null; if (validationResult.IsValid) { tblT_Cost cost = Insert(costDTO, dateStamp); Db.SaveChanges(); success = true; model = costEntryDataProvider.Get(cost.Cost_PK); } return(new SaveResult <CostEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public DeleteResult <tblT_Cost> Execute(int costPK, DeleteMethod deleteMethod) { tblT_Cost cost = Db.tblT_Cost.Find(costPK); if (cost == null) { return(new DeleteResult <tblT_Cost>() { Success = false, Message = $"Id '{costPK}' is not found.", Record = null }); } switch (deleteMethod) { case DeleteMethod.Soft: SoftDelete(cost); break; case DeleteMethod.Hard: HardDelete(cost); break; default: break; } Db.SaveChanges(); return(new DeleteResult <tblT_Cost>() { Success = true, Message = $"Cost with Id '{costPK}' successfully deleted.", Record = cost }); }