Beispiel #1
0
        public HttpResponseMessage UpdateCollection(ApiModels.TrnCollectionModel objCollection, String id)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.AspNetUserId == User.Identity.GetUserId()
                                  select d;

                var customer = from d in db.MstCustomers
                               where d.Id == objCollection.CustomerId
                               select d;

                if (customer.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Customer not found."));
                }

                var loan = from d in db.TrnLoans
                           where d.Id == objCollection.LoanId &&
                           d.CustomerId == customer.FirstOrDefault().Id
                           select d;

                if (loan.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Loan transaction not found."));
                }

                var payType = from d in db.MstPayTypes
                              where d.Id == objCollection.PayTypeId
                              select d;

                if (payType.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Pay type not found."));
                }

                var collector = from d in db.MstCollectors
                                where d.Id == objCollection.CollectorId
                                select d;

                if (collector.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Collector not found."));
                }

                var collection = from d in db.TrnCollections
                                 where d.Id == Convert.ToInt32(id)
                                 select d;

                if (collection.Any())
                {
                    var updateCollection = collection.FirstOrDefault();
                    updateCollection.CollectionDate       = Convert.ToDateTime(objCollection.CollectionDate);
                    updateCollection.CustomerId           = customer.FirstOrDefault().Id;
                    updateCollection.LoanId               = loan.FirstOrDefault().Id;
                    updateCollection.PayTypeId            = payType.FirstOrDefault().Id;
                    updateCollection.PaymayaAccountNumber = objCollection.PaymayaAccountNumber;
                    updateCollection.GCashAccountNumber   = objCollection.GCashAccountNumber;
                    updateCollection.CreditCardNumber     = objCollection.CreditCardNumber;
                    updateCollection.CreditCardName       = objCollection.CreditCardName;
                    updateCollection.CheckNumber          = objCollection.CheckNumber;
                    updateCollection.CheckDate            = Convert.ToDateTime(objCollection.CheckDate);
                    updateCollection.CheckBank            = objCollection.CheckBank;
                    updateCollection.PaidAmount           = objCollection.PaidAmount;
                    updateCollection.PenaltyAmount        = objCollection.PenaltyAmount;
                    updateCollection.Remarks              = objCollection.Remarks;
                    updateCollection.CollectorId          = collector.FirstOrDefault().Id;
                    updateCollection.UpdatedByUserId      = currentUser.FirstOrDefault().Id;
                    updateCollection.UpdatedDateTime      = DateTime.Now;
                    db.SubmitChanges();

                    UpdateLoanTransaction(loan.FirstOrDefault().Id);

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Collection not found."));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
        public HttpResponseMessage AddCollection(ApiModels.TrnCollectionModel objCollection)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.AspNetUserId == User.Identity.GetUserId()
                                  select d;

                var customer = from d in db.MstCustomers
                               where d.Id == objCollection.CustomerId
                               select d;

                if (customer.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Customer not found."));
                }

                var loan = from d in db.TrnLoans
                           where d.Id == objCollection.LoanId &&
                           d.CustomerId == customer.FirstOrDefault().Id
                           select d;

                if (loan.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Loan transaction not found."));
                }

                var payType = from d in db.MstPayTypes
                              where d.Id == objCollection.PayTypeId
                              select d;

                if (payType.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Pay type not found."));
                }

                var collector = from d in db.MstCollectors
                                where d.Id == objCollection.CollectorId
                                select d;

                if (collector.Any() == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Collector not found."));
                }

                var collectionNumber = "0000000001";
                var lastCollection   = from d in db.TrnCollections.OrderByDescending(d => d.Id)
                                       select d;

                if (lastCollection.Any())
                {
                    var lastCollectionNumber = Convert.ToInt32(lastCollection.FirstOrDefault().CollectionNumber) + 0000000001;
                    collectionNumber = LeadingZeroes(lastCollectionNumber, 10);
                }

                Data.TrnCollection newCollection = new Data.TrnCollection()
                {
                    CollectionNumber       = collectionNumber,
                    CollectionDate         = Convert.ToDateTime(objCollection.CollectionDate),
                    ManualCollectionNumber = collectionNumber,
                    CustomerId             = customer.FirstOrDefault().Id,
                    LoanId               = loan.FirstOrDefault().Id,
                    PayTypeId            = payType.FirstOrDefault().Id,
                    PaymayaAccountNumber = objCollection.PaymayaAccountNumber,
                    GCashAccountNumber   = objCollection.GCashAccountNumber,
                    CreditCardNumber     = objCollection.CreditCardNumber,
                    CreditCardName       = objCollection.CreditCardName,
                    CheckNumber          = objCollection.CheckNumber,
                    CheckDate            = Convert.ToDateTime(objCollection.CheckDate),
                    CheckBank            = objCollection.CheckBank,
                    PaidAmount           = objCollection.PaidAmount,
                    PenaltyAmount        = objCollection.PenaltyAmount,
                    Remarks              = objCollection.Remarks,
                    CollectorId          = collector.FirstOrDefault().Id,
                    IsLocked             = true,
                    CreatedByUserId      = currentUser.FirstOrDefault().Id,
                    CreatedDateTime      = DateTime.Now,
                    UpdatedByUserId      = currentUser.FirstOrDefault().Id,
                    UpdatedDateTime      = DateTime.Now
                };

                db.TrnCollections.InsertOnSubmit(newCollection);
                db.SubmitChanges();

                UpdateLoanTransaction(loan.FirstOrDefault().Id);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }