예제 #1
0
        public void TestCreateSameSerialNumberProductUnitAsync()
        {
            ContextSeeder.Seed();
            var braBo = new BrandBusinessObject();
            var bra   = new Brand("Barraca do Tejo");

            braBo.Create(bra);
            var catBo = new CategoryBusinessObject();
            var cat   = new Category("Non-Alcoholic Beverages");

            catBo.Create(cat);
            var pmbo    = new ProductModelBusinessObject();
            var prodMod = new ProductModel("Vinho Branco", "506-1237-422", "", 4.24, 0.80, Measure.L, bra.Id, cat.Id);

            pmbo.Create(prodMod);
            var sbo = new ShoppingBasketBusinessObject();
            var sbk = sbo.ListNotDeleted().Result.First();

            var bo        = new ProductUnitBusinessObject();
            var item      = bo.ListAsync().Result.Result.FirstOrDefault();
            var ebo       = new EstablishmentBusinessObject();
            var est       = ebo.ListNotDeleted().Result.First();
            var prodUnit  = new ProductUnit(item.SerialNumber, false, prodMod.Id, est.Id, sbk.Id);
            var resCreate = bo.CreateAsync(prodUnit).Result;

            Assert.IsTrue(!resCreate.Result);
        }
예제 #2
0
        public void TestCreateAndReadProductUnitAsync()
        {
            ContextSeeder.Seed();

            var pmbo    = new ProductModelBusinessObject();
            var prodMod = pmbo.ListNotDeletedAsync().Result.Result.First();
            var ebo     = new EstablishmentBusinessObject();
            var est     = ebo.ListNotDeleted().Result.First();
            var sbo     = new ShoppingBasketBusinessObject();
            var sbk     = sbo.ListNotDeleted().Result.First();

            var bo        = new ProductUnitBusinessObject();
            var prodUnit  = new ProductUnit("werkyt235", false, prodMod.Id, est.Id, sbk.Id);
            var resCreate = bo.CreateAsync(prodUnit).Result;

            var resGet = bo.ReadAsync(prodUnit.Id).Result;

            Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null);
        }
        public async Task <IActionResult> Create(ProductUnitViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    var listEOperation = await _ebo.ListNotDeletedAsync();

                    if (!listEOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listEOperation.Exception));
                    }

                    var eList = new List <SelectListItem>();
                    foreach (var item in listEOperation.Result)
                    {
                        var company = await _cbo.ReadAsync(item.CompanyId);

                        eList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = company.Result.Name + ", " + item.Address
                        });
                    }

                    var listSBOperation = await _sbbo.ListNotDeletedAsync();

                    if (!listSBOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listSBOperation.Exception));
                    }

                    var sbList = new List <SelectListItem>();
                    foreach (var item in listSBOperation.Result)
                    {
                        var profile = await _pbo.ReadAsync(item.ProfileId);

                        sbList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = profile.Result.VatNumber.ToString()
                        });
                    }

                    var listPMOperation = await _pmbo.ListNotDeletedAsync();

                    if (!listPMOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listPMOperation.Exception));
                    }

                    var pmList = new List <SelectListItem>();
                    foreach (var item in listPMOperation.Result)
                    {
                        pmList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = item.Name
                        });
                    }

                    ViewBag.Establishments  = eList;
                    ViewBag.ShoppingBaskets = sbList;
                    ViewBag.ProductModels   = pmList;

                    Draw("Create", "fa-plus");

                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }