Esempio n. 1
0
        // Print Invoice

        public ActionResult Invoice(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductReceive productReceive = _productReceiveService.FindById(id.Value);

            if (productReceive == null)
            {
                return(HttpNotFound());
            }

            var productReceiveLineItemViewModels = new List <ProductReceiveLineItemViewModel>();

            foreach (var productReceiveLineItem in productReceive.ProductReceiveLineItems)
            {
                var productReceiveLineItemviewModel = new ProductReceiveLineItemViewModel()
                {
                    ProductReceiveLineItemId = productReceiveLineItem.ProductReceiveLineItemId,
                    ProductId   = productReceiveLineItem.ProductId,
                    Productname = _productService.FindBy(s => s.ProductcId == productReceiveLineItem.ProductId).First().ProductName,
                    Quantity    = productReceiveLineItem.Quantity,
                    UnitCost    = productReceiveLineItem.UnitCost,
                    UnitPrice   = _productService.FindBy(s => s.ProductcId == productReceiveLineItem.ProductId).First().UnitPrice
                };
                productReceiveLineItemViewModels.Add(productReceiveLineItemviewModel);
            }

            ViewBag.LineItems = productReceiveLineItemViewModels;
            MyIdentityUser user = userManager.FindById(productReceive.UserId);

            ViewBag.UserName = user.FullName;
            return(View(productReceive));
        }
Esempio n. 2
0
        // GET: ProductReceives/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 productReceive          = _productReceiveService.Get(t => t.ProductReceiveId == id, null, "ProductReceiveLineItems").FirstOrDefault();
                var productReceiveViewModel = new ProductReceiveViewModel()
                {
                    BranchId         = productReceive.BranchId,
                    BranchName       = productReceive.Branch.BranchName,
                    DateReceived     = productReceive.DateReceived,
                    ProductReceiveId = productReceive.ProductReceiveId,
                    UserId           = productReceive.UserId,
                    UserName         = userManager.FindById(productReceive.UserId).FullName
                };
                ViewBag.UserName         = user.FullName;
                ViewBag.BranchName       = _branchService.FindById(user.BranchId).BranchName;
                ViewBag.ProductReceiveId = productReceive.ProductReceiveId;
                var productReceiveLineItemViewModels = new List <ProductReceiveLineItemViewModel>();
                foreach (var productReceiveLineItem in productReceive.ProductReceiveLineItems)
                {
                    var productReceiveLineItemviewModel = new ProductReceiveLineItemViewModel()
                    {
                        ProductReceiveLineItemId = productReceiveLineItem.ProductReceiveLineItemId,
                        ProductId   = productReceiveLineItem.ProductId,
                        Productname = _productService.FindBy(s => s.ProductcId == productReceiveLineItem.ProductId).First().ProductName,
                        Quantity    = productReceiveLineItem.Quantity,
                        UnitCost    = productReceiveLineItem.UnitCost
                    };
                    productReceiveLineItemViewModels.Add(productReceiveLineItemviewModel);
                }
                ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName");
                ViewData["BranchList"]  = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName");
                ViewBag.ProductReceiveLineItemViewModels = productReceiveLineItemViewModels;
                ViewBag.UserName   = user.FullName;
                ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName;
                return(View(productReceiveViewModel));
            }

            ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName");
            ViewData["BranchList"]  = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName");
            ViewBag.UserName        = user.FullName;
            ViewBag.BranchName      = _branchService.FindById(user.BranchId).BranchName;

            return(View());
        }
Esempio n. 3
0
        public ActionResult AddLineItem([Bind(Include = "ProductReceiveId,Quantity,ProductId,UnitCost")] ProductReceiveLineItemViewModel productReceiveLineItemViewModel)
        {
            var productReceive = _productReceiveService.Get(t => t.ProductReceiveId == productReceiveLineItemViewModel.ProductReceiveId, null, "ProductReceiveLineItems").FirstOrDefault();
            int exists         = productReceive.ProductReceiveLineItems.Where(t => t.ProductId == productReceiveLineItemViewModel.ProductId).ToList().Count;

            if (exists > 0)
            {
                return(RedirectToAction("Create", "ProductReceives", new { id = productReceive.ProductReceiveId }));
            }
            var productReceiveLineItem = new ProductReceiveLineItem()
            {
                ProductId        = productReceiveLineItemViewModel.ProductId,
                Quantity         = productReceiveLineItemViewModel.Quantity,
                ProductReceiveId = productReceiveLineItemViewModel.ProductReceiveId,
                UnitCost         = productReceiveLineItemViewModel.UnitCost, //_productService.FindById(productReceiveLineItemViewModel.ProductId).UnitCost
            };

            productReceive.ProductReceiveLineItems.Add(productReceiveLineItem);
            _productReceiveService.AddProductReceiveLineItem(productReceive, productReceiveLineItem);
            return(RedirectToAction("Create", "ProductReceives", new { id = productReceive.ProductReceiveId }));
        }