Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(IncomeMVCModel income)
        {
            if (income == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            IncomeEFModel deletingIncome = incomeService.GetById(income.Id);
            if (income == null)
            {
                return HttpNotFound(String.Format("Income with Id {0} not found.", income.Id));
            }

            incomeService.Delete(deletingIncome);
            incomeService.Save();

            return RedirectToAction("Index");
        }
        public void CanUpdateIncomeModelPropertiesByTheirId()
        {
            // Creating simple model
            IncomeMVCModel income = new IncomeMVCModel
            {
                Id = 2,
                Products = new List<IncomeMVCModel.ProductDetailsModel>
                {
                    new IncomeMVCModel.ProductDetailsModel
                    {
                        Product = new ProductMVCModel { Id = 2 },
                        Sizes = new List<IncomeMVCModel.ProductDetailsModel.SizeDetailsModel>
                        {
                            new IncomeMVCModel.ProductDetailsModel.SizeDetailsModel() {Size = new SizeMVCModel {Id = 3 } }
                        }
                    }
                }
            };

            income.UpdateModelPropertiesFromDomainModel(productService, sizeService);

            Assert.AreEqual(productService.GetById(2).Article, income.Products[0].Product.Article);
            Assert.AreEqual(sizeService.GetById(3).Id, income.Products[0].Sizes[0].Size.Id);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(IncomeMVCModel income, string inputSave, Guid? inputDeletingDetailsGuid, string addProductDetails)
        {
            if (income == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            income.UpdateModelPropertiesFromDomainModel(productService, sizeService);

            if (inputDeletingDetailsGuid != null)
            {
                var removingItem = income.Products.Find(p => p.Guid == inputDeletingDetailsGuid);

                if (!income.Products.Remove(removingItem))
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Failed to delete unexisting item");
                }

                ViewData.ModelState.Clear();

                return View(income);
            }

            if (!String.IsNullOrWhiteSpace(addProductDetails))
            {
                // Add new product.

                // Return updated View
            }

            if (!String.IsNullOrWhiteSpace(inputSave) && ModelState.IsValid)
            {

                var incomeDomain = income.ToDomainModel(incomeService, productService, sizeService);

                if (incomeDomain.IsNew())
                {
                    incomeService.Add(income.ToDomainModel(incomeService, productService, sizeService));
                }
                else
                {
                    incomeService.Update(incomeDomain);
                }

                incomeService.Save();

                return RedirectToAction("Index");
            }

            return View(income);
        }