Exemple #1
0
        public async Task <IActionResult> AddBenefit(CreateBenefitViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    await _partnerRepository.AddBenefitAsync(model);

                    return(this.RedirectToAction($"Details/{model.PartnerId}"));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There are a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            return(this.View(model));
        }
Exemple #2
0
        public async Task AddBenefitAsync(CreateBenefitViewModel model)
        {
            var partner = await this.GetParnerWithBenefitsAsync(model.PartnerId);

            if (partner == null)
            {
                return;
            }

            partner.Benefits.Add(new Benefit {
                Description = model.Description, Reward = model.Reward, IsPercentage = model.IsPercentage
            });
            _context.Partners.Update(partner);
            await _context.SaveChangesAsync();
        }
Exemple #3
0
        public async Task <IActionResult> AddBenefit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var partner = await _partnerRepository.GetByIdAsync(id.Value);

            if (partner == null)
            {
                return(NotFound());
            }

            var model = new CreateBenefitViewModel {
                PartnerId = partner.Id
            };

            return(View(model));
        }