public ActionResult SaveStockIn(string InvoiceNo, string Notes, List <StockIn> stockIns) { StockIn result = new StockIn(); var brands = _brandService.GetAll(); var sizes = _sizeService.GetAll(); var apis = _apiService.GetAll(); var stockOutInvoice = ""; foreach (var item in stockIns) { var brand = brands.Where(a => a.Id == item.BrandId).FirstOrDefault(); var size = sizes.Where(a => a.Id == item.SizeId).FirstOrDefault(); var api = apis.Where(a => a.Id == item.APIId).FirstOrDefault(); item.Notes = Notes; item.InvoiceNo = InvoiceNo; item.BrandName = brand.BrandName; item.APIName = item.APIName; item.SizeName = size.Name; item.CreatedDate = DateTime.Now; item.CreatedBy = CurrentSession.GetCurrentSession().UserName; if (!item.ProductionDate.HasValue) { item.ProductionDate = DateTime.Now; } item.StockInPrice = item.Rate * item.BaleQty; serviceStockIn.Save(item); stockOutInvoice = item.StockOutInvoiceNo; } //stocOut Invoice Update var stockOuts = stockOutService.GetStockChallan(stockOutInvoice); foreach (var item in stockOuts) { item.AlreadyProcessed = true; item.UpdatedDate = DateTime.Now; item.UpdatedBy = CurrentSession.GetCurrentSession().UserName; stockOutService.Update(item, item.Id); } return(Json(true, JsonRequestBehavior.AllowGet)); }