Пример #1
0
        public int Insert(CustomerPaymentDetail obj)
        {
            CustomerPaymentDetail newCustomerPaymentDetail = new CustomerPaymentDetail();

            newCustomerPaymentDetail.cust_Id       = obj.cust_Id;
            newCustomerPaymentDetail.balanceAmount = obj.balanceAmount;
            newCustomerPaymentDetail.PaidAmount    = obj.PaidAmount;
            newCustomerPaymentDetail.date          = obj.date;
            newCustomerPaymentDetail.received      = obj.received;

            newCustomerPaymentDetail.remark    = obj.remark;
            newCustomerPaymentDetail.signature = obj.signature;
            context.CustomerPaymentDetails.Add(newCustomerPaymentDetail);
            context.SaveChanges();

            CustomerDetail objCustomerDetails = context.CustomerDetails.Where(ite => ite.cust_id == obj.cust_Id).FirstOrDefault();

            if (objCustomerDetails != null)
            {
                objCustomerDetails.openingBalance = objCustomerDetails.openingBalance - obj.PaidAmount;
                context.SaveChanges();
            }
            return(newCustomerPaymentDetail.cust_Id);
        }
        public int Insert(DeliveryDetail obj)
        {
            try
            {
                DeliveryDetail newdeliverydetail = new DeliveryDetail();
                newdeliverydetail.C_deliveryDate      = obj.C_deliveryDate;
                newdeliverydetail.voucherNo           = obj.voucherNo;
                newdeliverydetail.cylinder_Id         = obj.cylinder_Id;
                newdeliverydetail.cust_id             = obj.cust_id;
                newdeliverydetail.cylinderAmount      = obj.cylinderAmount;
                newdeliverydetail.emptyCylinder       = obj.emptyCylinder;
                newdeliverydetail.filledCylinder      = obj.filledCylinder;
                newdeliverydetail.replacementCylinder = obj.replacementCylinder;
                newdeliverydetail.paidAmount          = obj.paidAmount;
                newdeliverydetail.totalAmount         = obj.totalAmount;
                newdeliverydetail.sgst          = Math.Round(obj.sgst.Value);
                newdeliverydetail.cgst          = Math.Round(obj.cgst.Value);
                newdeliverydetail.balanceAmount = obj.balanceAmount;
                newdeliverydetail.userid        = obj.userid;
                if (obj.signature != null)
                {
                    newdeliverydetail.signature = obj.signature;
                }
                if (obj.phone != null)
                {
                    newdeliverydetail.phone = obj.phone;
                }

                if (obj.filledCylinder <= 0)
                {
                    obj.voucherNo = "LPG-E000";
                }
                context.DeliveryDetails.Add(newdeliverydetail);
                context.SaveChanges();

                CustomerDetail objCustomerDetails = context.CustomerDetails.Where(ite => ite.cust_id == obj.cust_id).FirstOrDefault();
                if (objCustomerDetails != null)
                {
                    objCustomerDetails.openingBalance = objCustomerDetails.openingBalance + obj.balanceAmount;
                    context.SaveChanges();
                }

                CustomerCylinderDetail objCustomerCylinderDetail = context.CustomerCylinderDetails.Where(ite => ite.cust_id == obj.cust_id && ite.cylinder_Id == obj.cylinder_Id).FirstOrDefault();
                if (objCustomerCylinderDetail != null)
                {
                    if (obj.filledCylinder > 0)
                    {
                        objCustomerCylinderDetail.totalCylinder = objCustomerCylinderDetail.totalCylinder + obj.filledCylinder;
                    }
                    if (obj.emptyCylinder > 0)
                    {
                        objCustomerCylinderDetail.totalCylinder = objCustomerCylinderDetail.totalCylinder - obj.emptyCylinder;
                    }
                    if (obj.replacementCylinder > 0)
                    {
                        objCustomerCylinderDetail.totalCylinder = objCustomerCylinderDetail.totalCylinder - obj.replacementCylinder;
                    }



                    context.SaveChanges();
                }
                return(newdeliverydetail.ID);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                // ViewBag.ErrorMsg = "Sorry Some Problem Occured";
                //dd.cylinders = repo.GetCylinderType();
                //return View(dd);
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }