Beispiel #1
0
        public int Insert(CustomerDetail obj)
        {
            CustomerDetail newCustomerMaster = new CustomerDetail();

            //   CustomerCylinderDetail newCustomerCylinderDetail = new CustomerCylinderDetail();
            newCustomerMaster.companyName    = obj.companyName;
            newCustomerMaster.address        = obj.address;
            newCustomerMaster.contact_Num_1  = obj.contact_Num_1;
            newCustomerMaster.contact_Num_2  = obj.contact_Num_2;
            newCustomerMaster.email          = obj.email;
            newCustomerMaster.discount       = obj.discount;
            newCustomerMaster.gst            = obj.gst;
            newCustomerMaster.balanceAmount  = obj.balanceAmount;
            newCustomerMaster.openingBalance = obj.openingBalance;
            context.CustomerDetails.Add(newCustomerMaster);
            context.SaveChanges();
            if (obj.CustomerCylinderDetail != null)
            {
                foreach (var i in obj.CustomerCylinderDetail)
                {
                    CustomerCylinderDetail newCustomerCylinderDetail = new CustomerCylinderDetail();
                    newCustomerCylinderDetail.cylinder_Id     = i.cylinder_Id;
                    newCustomerCylinderDetail.cylinderType    = i.cylinderType;
                    newCustomerCylinderDetail.discount        = i.discount;
                    newCustomerCylinderDetail.totalCylinder   = i.totalCylinder;
                    newCustomerCylinderDetail.openingCylinder = i.openingCylinder;
                    newCustomerCylinderDetail.cust_id         = newCustomerMaster.cust_id;
                    context.CustomerCylinderDetails.Add(newCustomerCylinderDetail);
                    context.SaveChanges();
                }
            }

            return(newCustomerMaster.cust_id);
        }
Beispiel #2
0
        public void Update(CustomerDetail obj)
        {
            CustomerDetail         newCustomerMaster         = context.CustomerDetails.Where(obj1 => obj1.cust_id == obj.cust_id).FirstOrDefault();
            CustomerCylinderDetail newCustomerCylinderDetail = new CustomerCylinderDetail();

            newCustomerMaster.companyName    = obj.companyName;
            newCustomerMaster.address        = obj.address;
            newCustomerMaster.contact_Num_1  = obj.contact_Num_1;
            newCustomerMaster.contact_Num_2  = obj.contact_Num_2;
            newCustomerMaster.email          = obj.email;
            newCustomerMaster.discount       = obj.discount;
            newCustomerMaster.gst            = obj.gst;
            newCustomerMaster.openingBalance = obj.openingBalance;
            newCustomerMaster.balanceAmount  = obj.balanceAmount;
            context.SaveChanges();
            if (obj.CustomerCylinderDetailForEdit != null)
            {
                foreach (var i in obj.CustomerCylinderDetailForEdit)
                {
                    newCustomerCylinderDetail.cylinder_Id     = i.cylinder_Id;
                    newCustomerCylinderDetail.cylinderType    = i.cylinderType;
                    newCustomerCylinderDetail.discount        = i.discount;
                    newCustomerCylinderDetail.totalCylinder   = i.totalCylinder;
                    newCustomerCylinderDetail.openingCylinder = i.openingCylinder;
                    newCustomerCylinderDetail.cust_id         = newCustomerMaster.cust_id;
                    context.CustomerCylinderDetails.Add(newCustomerCylinderDetail);
                    context.SaveChanges();
                }
            }
        }
Beispiel #3
0
        public void DeleteDetail(int id)
        {
            CustomerCylinderDetail newCustomerCylinder = context.CustomerCylinderDetails.Where(obj => obj.cust_id == id).FirstOrDefault();

            context.CustomerCylinderDetails.Remove(newCustomerCylinder);
            context.SaveChanges();
        }
        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;
            }
        }