public async Task<ActionResult> Add(AddProducerViewModel model, bool? backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                await this.BindCountryList(mediator);
                return View(model);
            }

            try
            {
                var request = model.ToRequest();

                await mediator.SendAsync(request);

                if (model.IsAddedToAddressBook)
                {
                    await mediator.SendAsync(producerAddressBookMap.Map(model));
                }

                return RedirectToAction("List", "Producer",
                    new { id = model.NotificationId, backToOverview });
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }
            await this.BindCountryList(mediator);
            return View(model);
        }
        public async Task<ActionResult> Add(Guid id, bool? backToOverview = null)
        {
            var model = new AddProducerViewModel { NotificationId = id };

            await this.BindCountryList(mediator);
            model.Address.DefaultCountryId = this.GetDefaultCountryId();

            return View(model);
        }
예제 #3
0
        public async Task Add_InvalidModel_ReturnsView()
        {
            var model = new AddProducerViewModel();

            producerController.ModelState.AddModelError("Test", "Error");

            var result = await producerController.Add(model) as ViewResult;

            Assert.Equal(string.Empty, result.ViewName);
        }
        public async Task Add_InvalidModel_ReturnsView()
        {
            var model = new AddProducerViewModel();

            producerController.ModelState.AddModelError("Test", "Error");

            var result = await producerController.Add(model) as ViewResult;

            Assert.Equal(string.Empty, result.ViewName);
        }
예제 #5
0
        public async Task <ActionResult> Add(Guid id, bool?backToOverview = null)
        {
            var model = new AddProducerViewModel {
                NotificationId = id
            };

            await this.BindCountryList(mediator);

            model.Address.DefaultCountryId = this.GetDefaultCountryId();

            return(View(model));
        }
예제 #6
0
        public async Task <ActionResult> Add(AddProducerViewModel model, bool?backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                await this.BindCountryList(mediator);

                return(View(model));
            }

            try
            {
                var request = model.ToRequest();

                await mediator.SendAsync(request);

                await this.auditService.AddAuditEntry(this.mediator,
                                                      model.NotificationId,
                                                      User.GetUserId(),
                                                      NotificationAuditType.Added,
                                                      NotificationAuditScreenType.Producer);

                if (model.IsAddedToAddressBook)
                {
                    await mediator.SendAsync(producerAddressBookMap.Map(model));
                }

                return(RedirectToAction("List", "Producer",
                                        new { id = model.NotificationId, backToOverview }));
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }
            await this.BindCountryList(mediator);

            return(View(model));
        }
예제 #7
0
        public async Task <ActionResult> Add(Guid id, AddProducerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                await this.BindCountryList(mediator);

                model.Address.DefaultCountryId = this.GetDefaultCountryId();

                return(View(model));
            }

            var request = new AddProducer
            {
                NotificationId = id,
                Address        = model.Address,
                Business       = model.Business.ToBusinessInfoData(),
                Contact        = model.Contact
            };

            await mediator.SendAsync(request);

            await this.auditService.AddAuditEntry(this.mediator,
                                                  id,
                                                  User.GetUserId(),
                                                  NotificationAuditType.Added,
                                                  NotificationAuditScreenType.Producer);

            if (model.IsAddedToAddressBook)
            {
                await mediator.SendAsync(new AddAddressBookEntry
                {
                    Address  = model.Address,
                    Business = model.Business.ToBusinessInfoData(),
                    Contact  = model.Contact,
                    Type     = AddressRecordType.Producer
                });
            }

            return(RedirectToAction("Index", "Overview"));
        }