コード例 #1
0
        public PayableInvoice GetSingle(string id, long companyId)
        {
            PayableInvoice invoice = this.GetAll(companyId)
                                     .FirstOrDefault(x => x.Id == Convert.ToInt32(id));

            return(invoice);
        }
コード例 #2
0
        public string Update(PayableInvoice entity)
        {
            PayableInvoice originalEntity = this.Context.PayableInvoices.Find(entity.Id);

            this.Context.Entry(originalEntity).CurrentValues.SetValues(entity);
            this.Context.Entry(originalEntity).State = EntityState.Modified;
            this.Commit();
            return(entity.Id.ToString());
        }
コード例 #3
0
 public string Update(PayableInvoice entity)
 {
     if (entity.IsValid())
     {
         return(this.repository.Update(entity));
     }
     else
     {
         return("Entity is not in valid state");
     }
 }
コード例 #4
0
        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);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        public PayableInvoice GetSingle(long companyId, long sobId, long periodId)
        {
            IEnumerable <PayableInvoice> entityList = this.GetAll(companyId);

            if (entityList.Count() > 0)
            {
                PayableInvoice entity = entityList.Where(x => x.SOBId == sobId && x.PeriodId == periodId)
                                        .OrderByDescending(rec => rec.Id).First();
                return(entity);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
 public PayableInvoiceModel(PayableInvoice entity)
 {
     this.Amount        = entity.Amount;
     this.CompanyId     = AuthenticationHelper.CompanyId.Value; // entity.CompanyId;
     this.CreateBy      = entity.CreateBy;
     this.CreateDate    = entity.CreateDate;
     this.Id            = entity.Id;
     this.InvoiceDate   = entity.InvoiceDate;
     this.InvoiceNo     = entity.InvoiceNo;
     this.InvoiceTypeId = entity.InvoiceTypeId;
     this.PeriodId      = entity.PeriodId;
     this.Remarks       = entity.Remarks;
     this.SOBId         = entity.SOBId;
     this.Status        = entity.Status;
     this.UpdateBy      = entity.UpdateBy;
     this.UpdateDate    = entity.UpdateDate;
     this.VendorId      = entity.VendorId;
     this.VendorSiteId  = entity.VendorSiteId;
     this.WHTaxId       = entity.WHTaxId;
 }
コード例 #7
0
        private static PayableInvoice getEntityByModel(PayableInvoiceModel model)
        {
            if (model == null)
            {
                return(null);
            }

            PayableInvoice entity = new PayableInvoice();

            if (model.Id == 0)
            {
                entity.CreateBy   = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
                entity.CompanyId  = AuthenticationHelper.CompanyId.Value;
            }
            else
            {
                entity.CreateBy   = model.CreateBy;
                entity.CreateDate = model.CreateDate;
                entity.CompanyId  = model.CompanyId;
            }

            entity.Amount        = model.Amount;
            entity.Id            = model.Id;
            entity.InvoiceDate   = model.InvoiceDate;
            entity.InvoiceNo     = model.InvoiceNo;
            entity.InvoiceTypeId = model.InvoiceTypeId;
            entity.PeriodId      = model.PeriodId;
            entity.Remarks       = model.Remarks;
            entity.SOBId         = model.SOBId;
            entity.Status        = model.Status;
            entity.UpdateBy      = model.UpdateBy;
            entity.UpdateDate    = model.UpdateDate;
            entity.VendorId      = model.VendorId;
            entity.VendorSiteId  = model.VendorSiteId;
            entity.WHTaxId       = model.WHTaxId;
            return(entity);
        }
コード例 #8
0
 public string Insert(PayableInvoice entity)
 {
     this.Context.PayableInvoices.Add(entity);
     this.Commit();
     return(entity.Id.ToString());
 }