private static PayableInvoiceDetail getEntityByModel(PayableInvoiceDetailModel model, int count) { if (model == null) { return(null); } PayableInvoiceDetail entity = new PayableInvoiceDetail(); if (count == 0) { entity.CreateBy = AuthenticationHelper.UserId; entity.CreateDate = DateTime.Now; } else { entity.CreateBy = model.CreateBy; entity.CreateDate = model.CreateDate; } entity.Amount = model.Amount; entity.CodeCombinationId = model.CodeCombinationId; entity.Description = model.Description; entity.Id = model.Id; entity.InvoiceId = model.InvoiceId; entity.UpdateBy = AuthenticationHelper.UserId; entity.UpdateDate = DateTime.Now; return(entity); }
public PayableInvoiceDetail GetSingle(string id, long companyId) { PayableInvoiceDetail entity = this.GetAll(companyId) .FirstOrDefault(x => x.Id == Convert.ToInt64(id)); return(entity); }
public string Update(PayableInvoiceDetail entity) { var originalEntity = this.Context.PayableInvoiceDetails.Find(entity.Id); this.Context.Entry(originalEntity).CurrentValues.SetValues(entity); this.Context.Entry(originalEntity).State = EntityState.Modified; this.Commit(); return(entity.Id.ToString()); }
public PayableInvoiceDetailModel(PayableInvoiceDetail entity) { this.Amount = entity.Amount; this.CodeCombinationId = entity.CodeCombinationId; this.CreateBy = entity.CreateBy; this.CreateDate = entity.CreateDate; this.Description = entity.Description; this.Id = entity.Id; this.InvoiceId = entity.InvoiceId; this.UpdateBy = entity.UpdateBy; this.UpdateDate = entity.UpdateDate; }
public static void Update(PayableInvoiceModel payableInvoiceModel) { PayableInvoice entity = getEntityByModel(payableInvoiceModel); string result = string.Empty; if (entity.IsValid()) { if (payableInvoiceModel.Id > 0) { result = service.Update(entity); } else { result = service.Insert(entity); } if (!string.IsNullOrEmpty(result)) { var savedDetail = getInvoiceDetailByInvoiceId(result); if (savedDetail.Count() > payableInvoiceModel.InvoiceDetail.Count()) { var tobeDeleted = savedDetail.Take(savedDetail.Count() - payableInvoiceModel.InvoiceDetail.Count()); foreach (var item in tobeDeleted) { detailService.Delete(item.Id.ToString(), AuthenticationHelper.CompanyId.Value); } savedDetail = getInvoiceDetailByInvoiceId(result); } foreach (var detail in payableInvoiceModel.InvoiceDetail) { PayableInvoiceDetail detailEntity = getEntityByModel(detail, savedDetail.Count()); if (detailEntity.IsValid()) { detailEntity.InvoiceId = Convert.ToInt64(result); if (savedDetail.Count() > 0) { detailEntity.Id = savedDetail.FirstOrDefault().Id; savedDetail.Remove(savedDetail.FirstOrDefault(rec => rec.Id == detailEntity.Id)); detailService.Update(detailEntity); } else { detailService.Insert(detailEntity); } } } } } }
public string Update(PayableInvoiceDetail entity) { return(this.repository.Update(entity)); }
public string Insert(PayableInvoiceDetail entity) { return(this.repository.Insert(entity)); }
public string Insert(PayableInvoiceDetail entity) { this.Context.PayableInvoiceDetails.Add(entity); this.Commit(); return(entity.Id.ToString()); }