示例#1
0
        public async Task <IActionResult> Create(BrandViewModel 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);

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

                    return(View());
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
示例#2
0
        public void TestCreateAndReadBrandAsync()
        {
            ContextSeeder.Seed();
            var bo        = new BrandBusinessObject();
            var reg       = new Brand("Dona Ermelinda");
            var resCreate = bo.CreateAsync(reg).Result;
            var resGet    = bo.ReadAsync(reg.Id).Result;

            Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null);
        }
示例#3
0
        public void TestCreateSameNameBrandAsync()
        {
            ContextSeeder.Seed();
            var bo        = new BrandBusinessObject();
            var item      = bo.ListAsync().Result.Result.FirstOrDefault();
            var reg       = new Brand(item.Name);
            var resCreate = bo.CreateAsync(reg).Result;

            Assert.IsTrue(!resCreate.Result);
        }