public async Task <IActionResult> Create(ItemViewModel item) { var imgUrl = await fileService.UploadFile(item.UploadedImage); item.ImgUrl = imgUrl ?? item.ImgUrl; catalogueService.Create(item); return(RedirectToAction("GetAll")); }
public ActionResult Create(MainApplication model, FormCollection form) { model.CatalogueDetails = new Catalogue(); var detailsbefore = _CatalogueService.GetLastCatalogue(); int Catval = 0; int length = 0; if (detailsbefore != null) { Catval = detailsbefore.Id; Catval = Catval + 1; length = Catval.ToString().Length; } else { Catval = 1; length = 1; } string bookno = _UtilityService.getName("BN", length, Catval); model.CatalogueDetails.BookNumber = bookno; int count = Convert.ToInt32(form["hdnRowCount"]); for (int i = 1; i <= count; i++) { string typeOfMaterial = "materialType" + i; string colorCode = "colorCodeData" + i; string designCode = "designCodeData" + i; string designname = "designName" + i; string description = "itemDescription" + i; string size = "Size" + i; string unit = "Unit" + i; string brand = "Brand" + i; string costprice = "CostPrice" + i; string sellingprice = "SellingPrice" + i; string mrp = "MRP" + i; string subcategory = "subcategory" + i; string itemname = "itemname" + i; string itemtype = "ItemType" + i; string serialno = "serialno" + i; string suppliername = "supplier" + i; string numbertype = "NumberType" + i; if (form[itemname] != null) { model.CatalogueDetails = new Catalogue(); var itemdata = _ItemService.GetLastItem(); int itemval = 0; int lenght = 0; if (itemdata != null) { itemval = itemdata.itemId; itemval = itemval + 1; lenght = itemval.ToString().Length; } else { itemval = 1; lenght = 1; } string itemcode = _UtilityService.getName("I", lenght, itemval); model.CatalogueDetails.ItemCode = itemcode; model.CatalogueDetails.BookNumber = form["CatalogueDetails.BookNumber"]; model.CatalogueDetails.Category = form["CatalogueDetails.Category"]; if (form[colorCode] != "") { model.CatalogueDetails.Color = form[colorCode]; } else { model.CatalogueDetails.Color = null; } var colordetails = _ColorCodeService.GetcolorcodebyName(form[colorCode]); if (colordetails == null) { ColorCode color = new ColorCode(); color.colorName = model.CatalogueDetails.Color; var colordata = _ColorCodeService.GetLastColor(); int colorval = 0; int lengths = 0; if (colordata != null) { colorval = Convert.ToInt32(colordata.colorCode); colorval = Convert.ToInt32(colorval) + 1; lengths = colorval.ToString().Length; } else { colorval = 1; lengths = 1; } color.colorCode = colorval.ToString(); color.colorName = form[colorCode]; color.Status = "Active"; color.modifiedOn = DateTime.Now; _ColorCodeService.Create(color); } model.CatalogueDetails.Date = DateTime.Now; model.CatalogueDetails.ItemName = form[itemname]; if (form[costprice] != "") { model.CatalogueDetails.CostPrice = form[costprice]; } else { model.CatalogueDetails.CostPrice = "0"; } if (form[mrp] != "") { model.CatalogueDetails.MRP = form[mrp]; } else { model.CatalogueDetails.MRP = "0"; } if (form[sellingprice] != "") { model.CatalogueDetails.SellingPrice = form[sellingprice]; } else { model.CatalogueDetails.SellingPrice = "0"; } if (form[serialno] != "") { model.CatalogueDetails.SerialNumber = form[serialno]; } else { model.CatalogueDetails.SerialNumber = null; } model.CatalogueDetails.Brand = form[brand]; model.CatalogueDetails.Description = form[description]; model.CatalogueDetails.Design = form[designCode]; model.CatalogueDetails.DesignCode = form[designname]; model.CatalogueDetails.Size = form[size]; model.CatalogueDetails.ItemType = form["ItemType"]; model.CatalogueDetails.Status = "Active"; model.CatalogueDetails.Subcategory = form["CatalogueDetails.Subcategory"]; model.CatalogueDetails.SupplierName = form["supplier"]; model.CatalogueDetails.TypeOfMaterial = form[typeOfMaterial]; model.CatalogueDetails.Unit = form[unit]; model.CatalogueDetails.NumberType = form[numbertype]; model.CatalogueDetails.ModifiedOn = DateTime.Now; var details = _ItemNameService.GetDataByItemName(model.CatalogueDetails.ItemName); if (details == null) { model.ItemNameDetails = new ItemName(); model.ItemNameDetails.Name = model.CatalogueDetails.ItemName; model.ItemNameDetails.ItemCategory = model.CatalogueDetails.Category; model.ItemNameDetails.ItemSubcategory = model.CatalogueDetails.Subcategory; model.ItemNameDetails.ItemType = model.CatalogueDetails.ItemType; model.ItemNameDetails.DeleteStatus = "InActive"; model.ItemNameDetails.Status = "Active"; model.ItemNameDetails.ModifiedOn = DateTime.Now; _ItemNameService.Create(model.ItemNameDetails); } System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); string barcodeNo = string.Empty; //var Lastbarcode = _UniversalBarcodeNumber.GetLastBarcodeNumber(); var Lastbarcode = _UniversalBarcodeNumberService.GetLastBarcode(); int serialNo; /*To Check if it's the first barcode*/ if (Lastbarcode == null) { serialNo = 1111111; } else { int position = (Lastbarcode.Number.IndexOf(".") - 3); serialNo = Convert.ToInt32(Lastbarcode.Number.Substring(1, position)); serialNo += 1; } /*Creation Of Barcode*/ barcodeNo = model.CatalogueDetails.ItemName.Substring(0, 1).ToUpper() + serialNo.ToString() + model.CatalogueDetails.ItemName.Substring(model.CatalogueDetails.ItemName.Length - 1).ToUpper() + "U"; if (System.IO.File.Exists(Server.MapPath("../Barcode.txt"))) { System.IO.File.Delete(Server.MapPath("../BarCode.txt")); } System.IO.File.WriteAllText(Server.MapPath("../BarCode.txt"), barcodeNo); Process.Start(Server.MapPath("../BarCodeGenerate.exe")); imgBarCode.ImageUrl = "../../Images/" + barcodeNo + ".png"; /*Converting image into binary*/ string filepath = Server.MapPath("/Images/" + barcodeNo + ".png"); System.Threading.Thread.Sleep(1000); FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); /*Saving the Barcode Number*/ model.UniversalBarcodeNumberDetails = new UniversalBarcodeNumber(); model.UniversalBarcodeNumberDetails.Number = (barcodeNo + ".png").ToString(); model.UniversalBarcodeNumberDetails.BarcodeImage = bytes; model.UniversalBarcodeNumberDetails.ModifiedDate = DateTime.Now; _UniversalBarcodeNumberService.Create(model.UniversalBarcodeNumberDetails); model.CatalogueDetails.CatalogueBarcode = barcodeNo + ".png"; fs.Close(); br.Dispose(); var itemdetails = _ItemService.GetDescriptionByItemCode(model.CatalogueDetails.ItemCode); if (itemdetails != null) { if (itemdetails.brandName != model.CatalogueDetails.Brand && itemdetails.colorCode != model.CatalogueDetails.Color && itemdetails.costprice != model.CatalogueDetails.CostPrice && itemdetails.designCode != model.CatalogueDetails.DesignCode && itemdetails.designName != model.CatalogueDetails.Design && itemdetails.mrp != model.CatalogueDetails.MRP && itemdetails.sellingprice != model.CatalogueDetails.SellingPrice && itemdetails.size != model.CatalogueDetails.Size && itemdetails.typeOfMaterial != model.CatalogueDetails.TypeOfMaterial && itemdetails.unit != model.CatalogueDetails.Unit) { Item item = new Item(); item.UniversalBarcode = model.CatalogueDetails.CatalogueBarcode; item.brandName = model.CatalogueDetails.Brand; item.colorCode = model.CatalogueDetails.Color; item.costprice = model.CatalogueDetails.CostPrice; item.description = model.CatalogueDetails.Description; item.designCode = model.CatalogueDetails.DesignCode; item.designName = model.CatalogueDetails.Design; item.itemCategory = model.CatalogueDetails.Category; item.itemCode = model.CatalogueDetails.ItemCode; item.itemName = model.CatalogueDetails.ItemName; item.itemSubCategory = model.CatalogueDetails.Subcategory; item.itemtype = model.CatalogueDetails.ItemType; item.modifedOn = DateTime.Now; item.NumberType = model.CatalogueDetails.NumberType; item.mrp = model.CatalogueDetails.MRP; item.sellingprice = model.CatalogueDetails.SellingPrice; item.size = model.CatalogueDetails.Size; item.status = "Active"; item.typeOfMaterial = model.CatalogueDetails.TypeOfMaterial; item.unit = model.CatalogueDetails.Unit; if (item.sellingprice == null) { item.sellingprice = "0"; } if (item.mrp == null) { item.mrp = "0"; } _ItemService.createItem(item); } } else { Item item = new Item(); item.Barcode = model.CatalogueDetails.InwardBarcode; item.brandName = model.CatalogueDetails.Brand; item.colorCode = model.CatalogueDetails.Color; item.costprice = model.CatalogueDetails.CostPrice; item.description = model.CatalogueDetails.Description; item.designCode = model.CatalogueDetails.DesignCode; item.designName = model.CatalogueDetails.Design; item.itemCategory = model.CatalogueDetails.Category; item.itemCode = model.CatalogueDetails.ItemCode; item.itemName = model.CatalogueDetails.ItemName; item.itemSubCategory = model.CatalogueDetails.Subcategory; item.itemtype = model.CatalogueDetails.ItemType; item.modifedOn = DateTime.Now; item.NumberType = model.CatalogueDetails.NumberType; item.mrp = model.CatalogueDetails.MRP; item.sellingprice = model.CatalogueDetails.SellingPrice; item.size = model.CatalogueDetails.Size; item.status = "Active"; item.typeOfMaterial = model.CatalogueDetails.TypeOfMaterial; item.unit = model.CatalogueDetails.Unit; item.UniversalBarcode = model.CatalogueDetails.CatalogueBarcode; if (item.sellingprice == null) { item.sellingprice = "0"; } if (item.mrp == null) { item.mrp = "0"; } _ItemService.createItem(item); } FileInfo file = new FileInfo(filepath); if (file.Exists) { file.Delete(); } if (model.CatalogueDetails.SellingPrice == null) { model.CatalogueDetails.SellingPrice = "0"; } if (model.CatalogueDetails.MRP == null) { model.CatalogueDetails.MRP = "0"; } _CatalogueService.Create(model.CatalogueDetails); } } int detailsafter = _CatalogueService.GetLastCatalogue().Id; var cataloguebefore = Encode(Catval.ToString()); var catalogueafter = Encode(detailsafter.ToString()); return(RedirectToAction("Details/", "Catalogue", new { CatalogueBefore = cataloguebefore, CatalogueAfter = catalogueafter, })); }