public async Task Edit_InvalidModel_ReturnsView()
        {
            var model = new EditProducerViewModel();

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

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

            Assert.Equal(string.Empty, result.ViewName);
        }
        public async Task<ActionResult> Edit(Guid id, Guid entityId, bool? backToOverview = null)
        {
            var producer =
                await mediator.SendAsync(new GetProducerForNotification(id, entityId));

            var model = new EditProducerViewModel(producer);

            await this.BindCountryList(mediator);
            model.Address.DefaultCountryId = this.GetDefaultCountryId();
            return View(model);
        }
Beispiel #3
0
        public async Task <ActionResult> Edit(Guid id, Guid entityId, bool?backToOverview = null)
        {
            var producer =
                await mediator.SendAsync(new GetProducerForNotification(id, entityId));

            var model = new EditProducerViewModel(producer);

            await this.BindCountryList(mediator);

            model.Address.DefaultCountryId = this.GetDefaultCountryId();
            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, EditProducerViewModel producerModel)
        {
            if (id != producerModel.Producer.ProducerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (producerModel.Producer.ImageUpload != null)
                    {
                        //Store the image in a temp location as it comes back from the uploader
                        using (var memoryStream = new MemoryStream())
                        {
                            await producerModel.Producer.ImageUpload.CopyToAsync(memoryStream);

                            producerModel.Producer.ProducerImage = memoryStream.ToArray();
                        }
                    }
                    else
                    {
                        var imageFromDatabase = await _context.Producers.AsNoTracking()
                                                .FirstOrDefaultAsync(a => a.ProducerId == id);

                        producerModel.Producer.ProducerImage = imageFromDatabase.ProducerImage;
                    }

                    _context.Update(producerModel.Producer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProducerExists(producerModel.Producer.ProducerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(producerModel.Producer));
        }
        // GET: Producers/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var producer = await _context.Producers.FindAsync(id);

            if (producer == null)
            {
                return(NotFound());
            }
            EditProducerViewModel producerModel = new EditProducerViewModel();

            producerModel.Producer = producer;
            return(View(producerModel));
        }
Beispiel #6
0
        public async Task <ActionResult> Edit(EditProducerViewModel 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.Updated,
                                                      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));
        }
        public async Task Edit_InvalidModel_ReturnsView()
        {
            var model = new EditProducerViewModel();

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

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

            Assert.Equal(string.Empty, result.ViewName);
        }
        public async Task<ActionResult> Edit(EditProducerViewModel 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);
        }