private void btnSave_Click(object sender, EventArgs e) { var listNormDetails = grdData.Rows.Select(t => new ProductNormTemplateDetailModel() { ProductionMaterialId =Convert.ToInt32(t.Cells["MaterialId"].Value), BatchQuantity = Convert.ToDecimal(t.Cells["BatchQty"].Value), CartoonQuantity = Convert.ToDecimal(t.Cells["CartoonQty"].Value) }).ToList(); var normtemplateModel = new ProductNormTemplateModel() { OutputQuantity = txtOutputQty.Value, WasteQuantity = txtWasteQty.Value, PreparedBy = 1, PreparedDate = DateTime.Now.Date }; var proModel = new ProductModel() { BrandId = (int)cmbBrand.SelectedValue, ExerciseDuty = Convert.ToByte(chkExerciseDuty.Checked), IsVat = Convert.ToByte(chkVAT.Checked), FlavourId = (int)cmbFlavour.SelectedValue, ProductName = txtProductName.Text, SKUCode = txtProductName.Text, weight = float.Parse(txtWeight.Text), UnitOfMeasureId = (int)cmbUnit.SelectedValue, PacketPerCartoon = (int)txtPacketsPerCartoon.Value, PerCartoonRate = txtRatePerCartoon.Value, ProductNormTemplateModel = normtemplateModel, ProductNormTemplateDetailModels = listNormDetails, CreatedBy = 1, CreatedDate = DateTime.Now.Date, }; _productService.SaveProductAndNormTempalte(proModel); }
public ProductModel GetProductDetailsWithNormTemplateByProductId(int productId) { using (_context = new HSSNInventoryEntities()) { try { var data = _context.Products.Where(a => a.ProductId == productId).Select(productModel => new ProductModel() { ProductId = productModel.ProductId, BrandId = productModel.BrandId, ProductName = productModel.ProductName, FlavourId = productModel.FlavourId, SKUCode = productModel.SKUCode, weight = productModel.weight, UnitOfMeasureId = productModel.UnitOfMeasureId, PacketPerCartoon = productModel.PacketPerCartoon, PerCartoonRate = productModel.PerCartoonRate, IsVat = productModel.IsVat, ExerciseDuty = productModel.ExerciseDuty, CreatedBy = productModel.CreatedBy, CreatedDate = productModel.CreatedDate }).FirstOrDefault(); var normTempalte = _context.ProductNormTemplates.Where(a => a.ProductId == data.ProductId) .Select(productNormTemplate => new ProductNormTemplateModel() { ProductNormTemplateId = productNormTemplate.ProductNormTemplateId, ProductId = productNormTemplate.ProductId, OutputQuantity = productNormTemplate.OutputQuantity, WasteQuantity = productNormTemplate.WasteQuantity, PreparedBy = productNormTemplate.PreparedBy, PreparedDate = productNormTemplate.PreparedDate, ModifiedBy = productNormTemplate.ModifiedBy, ModifiedDate = productNormTemplate.ModifiedDate }).FirstOrDefault(); //-------------------------------------------------------------------- var normtempaleDetail = (from a in _context.ProductNormTemplateDetails join b in _context.ProductionMaterials on a.ProductionMaterialId equals b.ProductionMaterialId where a.ProductNormTemplateId == normTempalte.ProductNormTemplateId select new ProductNormTemplateDetailModel() { ProductNormTemplateId = normTempalte.ProductNormTemplateId, ProductionMaterialId = a.ProductionMaterialId, BatchQuantity = a.BatchQuantity, CartoonQuantity = a.CartoonQuantity, MaterialName = b.MaterialName }).ToList(); var model = new ProductModel(); model = data; model.ProductNormTemplateModel = normTempalte; model.ProductNormTemplateDetailModels = normtempaleDetail; return model; } catch (Exception) { throw; } } }
private ProductModel SaveProduct(ProductModel productModel) { using (_context = new HSSNInventoryEntities()) { try { var data = new Product() { BrandId = productModel.BrandId, ProductName = productModel.ProductName, FlavourId = productModel.FlavourId, SKUCode = productModel.SKUCode, weight = productModel.weight, UnitOfMeasureId = productModel.UnitOfMeasureId, PacketPerCartoon = productModel.PacketPerCartoon, PerCartoonRate = productModel.PerCartoonRate, IsVat = productModel.IsVat, ExerciseDuty = productModel.ExerciseDuty, CreatedBy = productModel.CreatedBy, CreatedDate = productModel.CreatedDate }; _context.Entry(data).State = EntityState.Added; _context.SaveChanges(); productModel.ProductId = data.ProductId; return productModel; } catch (Exception e) { throw; } } }
private bool EditProduct(ProductModel productModel) { using (_context = new HSSNInventoryEntities()) { try { var data = _context.Products.FirstOrDefault(a => a.ProductId == productModel.ProductId); if (data != null) { data.BrandId = productModel.BrandId; data.ProductName = productModel.ProductName; data.FlavourId = productModel.FlavourId; data.SKUCode = productModel.SKUCode; data.weight = productModel.weight; data.UnitOfMeasureId = productModel.UnitOfMeasureId; data.PacketPerCartoon = productModel.PacketPerCartoon; data.PacketPerCartoon = productModel.PacketPerCartoon; data.PerCartoonRate = productModel.PerCartoonRate; data.IsVat = productModel.IsVat; data.ExerciseDuty = productModel.ExerciseDuty; data.CreatedBy = productModel.CreatedBy; data.CreatedDate = productModel.CreatedDate; _context.Entry(data).State = EntityState.Modified; _context.SaveChanges(); productModel.ProductId = data.ProductId; } return true; } catch (Exception) { throw; } } }
public bool SaveProductAndNormTempalte(ProductModel productModel) { using (_context=new HSSNInventoryEntities()) { try { if (productModel.ProductId == 0) { var scope = new TransactionScope(); var model = SaveProduct(productModel); if (model.ProductId == 0) return false; productModel.ProductNormTemplateModel.ProductId = model.ProductId; var normtempModel = SaveNormTemplateSummary(productModel.ProductNormTemplateModel); if (normtempModel.ProductNormTemplateId == 0) return false; SaveProductNormTemplateDetail(productModel.ProductNormTemplateDetailModels, normtempModel.ProductNormTemplateId); scope.Complete(); return true; } else { var scope = new TransactionScope(); var isEdited = EditProduct(productModel); if (isEdited==false) return false; var normtempModel = EditNormTemplateSummary(productModel.ProductNormTemplateModel); if (normtempModel==false) return false; SaveProductNormTemplateDetail(productModel.ProductNormTemplateDetailModels, productModel.ProductNormTemplateModel.ProductNormTemplateId); scope.Complete(); return true; } } catch (Exception e) { throw; //Console.WriteLine(e); } } }