// GET: ProductTransfer/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var productTransfer = _productTransferService.Get(t => t.ProductTransferId == id, null, "ProductTransferLineItems").FirstOrDefault(); if (productTransfer == null) { return(HttpNotFound()); } var productTransferViewModel = new ProductTransferViewModel() { FromBranchId = productTransfer.FromBranchId, FromBranchName = _branchService.FindById(productTransfer.FromBranchId).BranchName, ToBranchId = productTransfer.ToBranchId, ToBranchName = _branchService.FindById(productTransfer.ToBranchId).BranchName, ProductTransferId = productTransfer.ProductTransferId, DateTransfered = productTransfer.DateTransfered, UserId = productTransfer.UserId, UserName = userManager.FindById(productTransfer.UserId).FullName }; var productTransferLineItemViewModels = new List <ProductTransferLineItemViewModel>(); foreach (var productTransferLineItem in productTransfer.ProductTransferLineItems) { var productTransferLineItemviewModel = new ProductTransferLineItemViewModel() { ProductTransferLineItemId = productTransferLineItem.ProductTransferLineItemId, ProductId = productTransferLineItem.ProductId, Productname = _productService.FindBy(s => s.ProductcId == productTransferLineItem.ProductId).First().ProductName, Quantity = productTransferLineItem.Quantity, UnitCost = _productService.FindBy(p => p.ProductcId == productTransferLineItem.ProductId).First().UnitCost }; productTransferLineItemViewModels.Add(productTransferLineItemviewModel); } ViewBag.ProductTransferLineItemViewModels = productTransferLineItemViewModels; return(View(productTransferViewModel)); }
public ActionResult AddLineItem([Bind(Include = "ProductTransferId,Quantity,ProductId")] ProductTransferLineItemViewModel productTransferLineItemViewModel) { var productTransfer = _productTransferService.Get(t => t.ProductTransferId == productTransferLineItemViewModel.ProductTransferId, null, "ProductTransferLineItems").FirstOrDefault(); int exists = productTransfer.ProductTransferLineItems.Where(t => t.ProductId == productTransferLineItemViewModel.ProductId).ToList().Count; bool available = _productTransferService.IsAvailable(productTransferLineItemViewModel.ProductId, productTransfer.FromBranchId, productTransferLineItemViewModel.Quantity); if (exists > 0 || !available) { return(RedirectToAction("Create", "ProductTransfers", new { id = productTransfer.ProductTransferId })); } var productTransferLineItem = new ProductTransferLineItem() { ProductId = productTransferLineItemViewModel.ProductId, Quantity = productTransferLineItemViewModel.Quantity, ProductTransferId = productTransferLineItemViewModel.ProductTransferId, }; productTransfer.ProductTransferLineItems.Add(productTransferLineItem); _productTransferService.AddProductTransferLineItem(productTransfer, productTransferLineItem); return(RedirectToAction("Create", "ProductTransfers", new { id = productTransfer.ProductTransferId })); }
// GET: ProductTransfer/Create public ActionResult Create(int?id) { MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); UserManager <MyIdentityUser> userManager = new UserManager <MyIdentityUser>(userStore); MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name); if (id != null && id != 0) { var productTransfer = _productTransferService.Get(t => t.ProductTransferId == id, null, "ProductTransferLineItems").FirstOrDefault(); var productTransferViewModel = new ProductTransferViewModel() { FromBranchId = productTransfer.FromBranchId, ToBranchId = productTransfer.ToBranchId, ProductTransferId = productTransfer.ProductTransferId, DateTransfered = productTransfer.DateTransfered, UserId = productTransfer.UserId, UserName = userManager.FindById(productTransfer.UserId).FullName }; //string FromBranchName = _branchService.FindById(productTransferViewModel.FromBranchId).BranchName; //string ToBranchName = _branchService.FindById(productTransferViewModel.ToBranchId).BranchName; //productTransferViewModel.FromBranchName = FromBranchName; //productTransferViewModel.ToBranchName = ToBranchName; //ViewBag.FromBranchName = FromBranchName; //ViewBag.ToBranchName = ToBranchName; string FromBranchName = _branchService.FindById(productTransferViewModel.FromBranchId).BranchName; string ToBranchName = _branchService.FindById(productTransferViewModel.ToBranchId).BranchName; productTransferViewModel.FromBranchName = FromBranchName; productTransferViewModel.ToBranchName = ToBranchName; ViewBag.FromBranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName", productTransfer.FromBranchId); ViewBag.ToBranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName", productTransfer.ToBranchId); ViewBag.UserName = user.FullName; ViewBag.ProductTransferId = productTransfer.ProductTransferId; var productTransferLineItemViewModels = new List <ProductTransferLineItemViewModel>(); foreach (var productTransferLineItem in productTransfer.ProductTransferLineItems) { var productTransferLineItemviewModel = new ProductTransferLineItemViewModel() { ProductTransferLineItemId = productTransferLineItem.ProductTransferLineItemId, ProductId = productTransferLineItem.ProductId, Productname = _productService.FindBy(s => s.ProductcId == productTransferLineItem.ProductId).First().ProductName, Quantity = productTransferLineItem.Quantity, }; productTransferLineItemViewModels.Add(productTransferLineItemviewModel); } ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName"); ViewBag.ProductTransferLineItemViewModels = productTransferLineItemViewModels; //ViewBag.UserName = user.FullName; //ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; return(View(productTransferViewModel)); } ViewBag.UserName = user.FullName; //ViewData["BranchList"] = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); //ViewBag.FromBranchName = _branchService.FindById(1).BranchName; ; //ViewBag.ToBranchName = _branchService.FindById(2).BranchName; ; ViewBag.FromBranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); ViewBag.ToBranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); return(View()); }