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; if (obj.signature != null) { 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(StaffPayment obj) { StaffPayment newStaffPaymentDetail = new StaffPayment(); newStaffPaymentDetail.Staff__ID = obj.Staff__ID; newStaffPaymentDetail.Received_By = obj.Received_By; newStaffPaymentDetail.Received_On = obj.Received_On; newStaffPaymentDetail.Return_Amount = obj.Return_Amount; newStaffPaymentDetail.Return_Date = obj.Return_Date; newStaffPaymentDetail.Balance_Amount = obj.Balance_Amount; context.StaffPayments.Add(newStaffPaymentDetail); context.SaveChanges(); return(newStaffPaymentDetail.ID); }
public int Insert(tbluser obj) { tbluser newUserMaster = new tbluser(); newUserMaster.firstname = obj.firstname; newUserMaster.lastname = obj.lastname; newUserMaster.passwordHash = obj.passwordHash; newUserMaster.username = obj.username; newUserMaster.role_id = obj.role_id; newUserMaster.phone = obj.phone; newUserMaster.isActive = obj.isActive; contextu.tblusers.Add(newUserMaster); contextu.SaveChanges(); return(newUserMaster.ID); }
public int Insert(LoadCylinder obj) { LoadCylinder newLoadMaster = new LoadCylinder(); newLoadMaster.user_id = obj.user_id; newLoadMaster.userName = obj.userName; newLoadMaster.loadDate = obj.loadDate; newLoadMaster.createdBy = obj.createdBy; newLoadMaster.createdOn = obj.createdOn; context.LoadCylinders.Add(newLoadMaster); context.SaveChanges(); if (obj.LoadDetail != null) { foreach (var i in obj.LoadDetail) { LoadDetail newLoadDetail = new LoadDetail(); newLoadDetail.cylinder_Id = i.cylinder_Id; newLoadDetail.cylinderType = i.cylinderType; newLoadDetail.FilledCylinder = i.FilledCylinder; var t = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id); var livecylinder = t.First(); if (t != null) { //livecylinder.FilledCylinderCount = livecylinder.FilledCylinderCount - i.FilledCylinder; //context.SaveChanges(); var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - i.FilledCylinder; if (fillecount <= 0) { livecylinder.FilledCylinderCount = 0; } else { livecylinder.FilledCylinderCount = fillecount; } context.SaveChanges(); } newLoadDetail.load_Id = newLoadMaster.ID; context.LoadDetails.Add(newLoadDetail); context.SaveChanges(); } } return(newLoadMaster.ID); }
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); }
public int Insert(CylinderMaster obj) { CylinderMaster newCustomerMaster = new CylinderMaster(); if (context.CylinderMasters.ToList() != null && context.CylinderMasters.ToList().Count > 0) { newCustomerMaster.ID = Convert.ToInt32(context.CylinderMasters.ToList().Last().ID) + 1; } else { newCustomerMaster.ID = 1; } // newCustomerMaster.ID = Convert.ToInt32(id.ID) + 1; newCustomerMaster.amount = Convert.ToDecimal(string.Format("{0:0.00}", obj.amount)); newCustomerMaster.cylinderType = obj.cylinderType; newCustomerMaster.openingEmpty = obj.openingEmpty; newCustomerMaster.openingFilled = obj.openingFilled; newCustomerMaster.openingReplace = obj.openingReplace; newCustomerMaster.CreatedOn = DateTime.Now; newCustomerMaster.CreatedBy = obj.CreatedBy; context.CylinderMasters.Add(newCustomerMaster); context.SaveChanges(); var livecylinderNew = new LiveCylinderDetail(); livecylinderNew.cylinder_Id = newCustomerMaster.ID; livecylinderNew.CylinderTypeName = newCustomerMaster.cylinderType; livecylinderNew.FilledCylinderCount = newCustomerMaster.openingFilled; livecylinderNew.EmptyCylinderCount = newCustomerMaster.openingEmpty; livecylinderNew.ReplacementCylinderCount = newCustomerMaster.openingReplace; context.LiveCylinderDetails.Add(livecylinderNew); context.SaveChanges(); return(newCustomerMaster.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; } }
public int Insert(PurchaseCylinder obj) { PurchaseCylinder newPurchaseMaster = new PurchaseCylinder(); // LiveCylinderDetail livecylinder = new LiveCylinderDetail(); newPurchaseMaster.PurchaseDetail = obj.PurchaseDetail; newPurchaseMaster.BillNo = obj.BillNo; newPurchaseMaster.dealerName = obj.dealerName; newPurchaseMaster.purchaseDate = obj.purchaseDate; newPurchaseMaster.amount = obj.amount; context.PurchaseCylinders.Add(newPurchaseMaster); context.SaveChanges(); if (obj.PurchaseDetail != null) { foreach (var i in obj.PurchaseDetail) { PurchaseDetail newpurchaseDetail = new PurchaseDetail(); newpurchaseDetail.cylinder_Id = i.cylinder_Id; newpurchaseDetail.cylinderType = i.cylinderType; newpurchaseDetail.FilledCylinder = i.FilledCylinder; var t = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id); var livecylinder = t.First(); if (t != null) { livecylinder.FilledCylinderCount = Convert.ToInt32(livecylinder.FilledCylinderCount) + i.FilledCylinder; context.SaveChanges(); } //var livecylinder = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id).FirstOrDefault(); //if (livecylinder != null) //{ // livecylinder.FilledCylinderCount= livecylinder.FilledCylinderCount + i.FilledCylinder; // context.SaveChanges(); //} //else //{ // var livecylinderNew = new LiveCylinderDetail(); // livecylinderNew.cylinder_Id = i.cylinder_Id; // livecylinderNew.CylinderTypeName = i.cylinderType; // livecylinderNew.FilledCylinderCount = i.FilledCylinder; // livecylinderNew.EmptyCylinderCount = 0; // livecylinderNew.ReplacementCylinderCount = 0; // context.LiveCylinderDetails.Add(livecylinderNew); // context.SaveChanges(); //} newpurchaseDetail.purchase_Id = newPurchaseMaster.ID; context.PurchaseDetails.Add(newpurchaseDetail); context.SaveChanges(); } } return(newPurchaseMaster.ID); }
public int Insert(UnloadCylinder obj) { UnloadCylinder newUnloadCylinder = new UnloadCylinder(); newUnloadCylinder.UnloadDetail = obj.UnloadDetail; newUnloadCylinder.user_id = obj.user_id; newUnloadCylinder.userName = obj.userName; newUnloadCylinder.UnloadDate = obj.UnloadDate; newUnloadCylinder.EmptyCylinder = obj.EmptyCylinder; newUnloadCylinder.createdBy = obj.createdBy; newUnloadCylinder.createdOn = obj.createdOn; context.UnloadCylinders.Add(newUnloadCylinder); context.SaveChanges(); if (obj.UnloadDetail != null) { foreach (var i in obj.UnloadDetail) { UnloadDetail newUnloadDetail = new UnloadDetail(); newUnloadDetail.cylinder_Id = i.cylinder_Id; newUnloadDetail.cylinderType = i.cylinderType; newUnloadDetail.EmptyCylinder = i.EmptyCylinder; newUnloadDetail.FilledCylinder = i.FilledCylinder; newUnloadDetail.RejectedCylinder = i.RejectedCylinder; var t = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id); var livecylinder = t.First(); if (t != null) { var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) + i.FilledCylinder; if (fillecount <= 0) { livecylinder.FilledCylinderCount = 0; } else { livecylinder.FilledCylinderCount = fillecount; } var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) + i.EmptyCylinder; if (emptycount <= 0) { livecylinder.EmptyCylinderCount = 0; } else { livecylinder.EmptyCylinderCount = emptycount; } var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) + i.RejectedCylinder; if (replacecount <= 0) { livecylinder.ReplacementCylinderCount = 0; } else { livecylinder.ReplacementCylinderCount = replacecount; } context.SaveChanges(); } newUnloadDetail.unload_Id = newUnloadCylinder.ID; context.UnloadDetails.Add(newUnloadDetail); var deliverycount = ( from delivery in context.DeliveryDetails where delivery.userid == obj.user_id && delivery.C_deliveryDate == obj.UnloadDate && delivery.unload_Flag == false select delivery ).FirstOrDefault(); if (deliverycount != null) { deliverycount.unload_Flag = true; context.SaveChanges(); } } } return(newUnloadCylinder.ID); }
public int Insert(ReturnCylinder obj) { ReturnCylinder newReturnMaster = new ReturnCylinder(); newReturnMaster.ERVNo = obj.ERVNo; newReturnMaster.dealerName = obj.dealerName; newReturnMaster.returnDate = obj.returnDate; context.ReturnCylinders.Add(newReturnMaster); context.SaveChanges(); if (obj.ReturnDetail != null) { foreach (var i in obj.ReturnDetail) { ReturnDetail newReturnDetail = new ReturnDetail(); newReturnDetail.cylinder_Id = i.cylinder_Id; newReturnDetail.cylinderType = i.cylinderType; newReturnDetail.FilledCylinder = i.FilledCylinder; newReturnDetail.EmptyCylinder = i.EmptyCylinder; newReturnDetail.RejectedCylinder = i.RejectedCylinder; var t = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id); var livecylinder = t.First(); if (t != null) { var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - i.FilledCylinder; if (fillecount <= 0) { livecylinder.FilledCylinderCount = 0; } else { livecylinder.FilledCylinderCount = fillecount; } var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) - i.EmptyCylinder; if (emptycount <= 0) { livecylinder.EmptyCylinderCount = 0; } else { livecylinder.EmptyCylinderCount = emptycount; } var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) - i.RejectedCylinder; if (replacecount <= 0) { livecylinder.ReplacementCylinderCount = 0; } else { livecylinder.ReplacementCylinderCount = replacecount; } context.SaveChanges(); } newReturnDetail.return_Id = newReturnMaster.ID; context.ReturnDetails.Add(newReturnDetail); context.SaveChanges(); } } return(newReturnMaster.ID); }