Esempio n. 1
0
        public ActionResult Create()
        {
            var reportProductVM = new ReportProductViewModel()
            {
                report = new Report()
                {
                    ID   = 0,
                    Date = DateTime.UtcNow
                }
            };

            return(View("ReportForm", reportProductVM));
        }
Esempio n. 2
0
        public ActionResult Save(ReportProductViewModel orderProductVM, int[] ProductIds)
        {
            if (!ModelState.IsValid)
            {
                return(View("ReportForm", orderProductVM));
            }
            if (ProductIds.Any(p => p == 0))
            {
                ModelState.AddModelError("", "Report must have at least one product, one of the products have not selected correctly!");
                return(View("ReportForm", orderProductVM));
            }

            var reportInDB = _unitOfWork.Reports.SingleOrDefault(r => r.ID == orderProductVM.report.ID);

            if (reportInDB is null)
            {
                var products = new List <Product>();
                foreach (var productId in ProductIds)
                {
                    var product = _unitOfWork.Products.Get(productId);
                    products.Add(product);
                }
                var report = new Report()
                {
                    ID       = orderProductVM.report.ID,
                    Date     = orderProductVM.report.Date,
                    Notes    = orderProductVM.report.Notes,
                    Products = products
                };
                _unitOfWork.Reports.Add(report);
            }
            else
            {
                reportInDB.Date  = orderProductVM.report.Date;
                reportInDB.Notes = orderProductVM.report.Notes;
                reportInDB.Products.Clear();
                foreach (var productId in ProductIds)
                {
                    var product = _unitOfWork.Products.Get(productId);
                    reportInDB.Products.Add(product);
                }
            }
            _unitOfWork.Complete();


            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        // TODO: Update method need to retrive products, that's retalted to report
        #region Update Operation
        public ActionResult Update(int id)
        {
            var reportInDb = _unitOfWork.Reports.GetReportWithProducts(id);

            if (reportInDb is null)
            {
                return(HttpNotFound());
            }

            var reportProductVM = new ReportProductViewModel()
            {
                report        = reportInDb,
                Products      = reportInDb.Products,
                AllCategories = _unitOfWork.Categories.GetAll(),
                AllProducts   = _unitOfWork.Products.GetAll()
            };

            return(View("ReportForm", reportProductVM));
        }
Esempio n. 4
0
        public ActionResult Create()
        {
            int reportId;

            if (!_unitOfWork.Reports.GetAll().Any())
            {
                reportId = 1;
            }
            else
            {
                reportId = _unitOfWork.Reports.GetAll().OrderBy(r => r.ID).Last().ID + 1;
            }
            var reportProductVM = new ReportProductViewModel()
            {
                report = new Report()
                {
                    ID   = reportId,
                    Date = DateTime.UtcNow
                }
            };

            return(View("ReportForm", reportProductVM));
        }