Example #1
0
        public void AddReceivable(ref dtoReceivable t)
        {
            var receivable = new tbl_receivable()
            {
                referenceNumber = t.referenceNumber,
                cashAmount = t.chequeAmount,
                chequeNumber = t.chequeNumber,
                chequeDate = t.chequeDate,
                chequeBank = t.chequeBank,
                dateCreated = DateTime.Now,
                createdBy = t.createdBy,
                clientId = t.clientId
            };

            DBContext.tbl_receivable.Add(receivable);
            DBContext.SaveChanges();

            t.receivableId = receivable.receivableId;
        }
Example #2
0
        public void SaveTransaction(dtoReceivable header, List<dtoReceivableDetail> details)
        {
            if (header.receivableId == 0)
            {
                tbl_receivable entiry = new tbl_receivable()
                {
                    receivableId = header.receivableId,
                    clientId = header.clientId,
                    isNewPayment = header.isNewPayment,
                    referenceNumber = header.referenceNumber,
                    isCash = header.isCash,
                    cashAmount = header.cashAmount,
                    chequeNumber = header.chequeNumber,
                    chequeDate = header.chequeDate,
                    chequeBank = header.chequeBank,
                    dateCreated = DateTime.Now
                };

                DBContext.tbl_receivable.Add(entiry);
                DBContext.SaveChanges();
                header.receivableId = entiry.receivableId;
            }
            else
            {

                var entity = DBContext.tbl_receivable.FirstOrDefault(d => d.receivableId == header.receivableId);

                entity.clientId = header.clientId;
                entity.isNewPayment = header.isNewPayment;
                entity.referenceNumber = header.referenceNumber;
                entity.isCash = header.isCash;
                entity.cashAmount = header.cashAmount;
                entity.chequeNumber = header.chequeNumber;
                entity.chequeDate = header.chequeDate;
                entity.chequeBank = header.chequeBank;
                entity.dateLastModified = DateTime.Now;

                var arr = details.Where(c=>c.receivableDetailsId != 0).Select(c => c.receivableDetailsId).ToArray<int>();
                var deleteList = DBContext.tbl_receivableDetails.Where(d => !arr.Contains(d.receivableDetailsId)
                && d.receivableId == header.receivableId);

                foreach (var item in deleteList)
                {
                    DBContext.tbl_receivableDetails.Remove(item);
                }
            }

            foreach (var item in details.Where(d => d.receivableDetailsId == 0))
            {

                DBContext.tbl_receivableDetails.Add(new tbl_receivableDetails {
                documentId = item.documentId,
                receivableId = header.receivableId,
                paymentPrice = item.paymentPrice,
                dateCreated = DateTime.Now,

                });
            }

            DBContext.SaveChanges();
        }
Example #3
0
        public dtoResult SaveReceivableTransaction(dtoReceivable header, List<dtoReceivableDetail> details)
        {
            var result = new dtoResult();
            try
            {
                if (header.isNew)
                {
                    AddReceivable(ref header);
                }

                if (details != null)
                    foreach (var item in details)
                    {
                       item.receivableId = header.receivableId;
                       item.paymentPrice = item.totalPayAmount;
                       item.createdBy = header.createdBy;
                       item.dateCreated = header.dateCreated;
                       AddReceivableDetail(item);
                    }

                DBContext.SaveChanges();
                result.isSuccessful = true;

            }
            catch (Exception ex)
            {
                result.isSuccessful = false;
                result.errorMsg = ex.ToString();
            }
            return result;
        }
Example #4
0
 public dtoResult SaveReceivableTransaction(dtoReceivable header, List<dtoReceivableDetail> details)
 {
     return repo.SaveReceivableTransaction(header, details);
 }