Esempio n. 1
0
        public async Task <IActionResult> Create()
        {
            var model = new SideEffectFormModel
            {
                SideEffectGroups = await this.populator.GetSideEffectGroups(),
                Drugs            = await this.populator.GetDrugs()
            };

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(SideEffectFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.SideEffectGroups = await this.populator.GetSideEffectGroups();

                model.Drugs = await this.populator.GetDrugs();

                return(View(model));
            }

            var dbModel = Mapper.Map <SideEffect>(model);

            var userId = this.userManager.GetUserId(User);

            dbModel.AdminId        = userId;
            dbModel.DateOfAddition = DateTime.UtcNow;

            var successfulCreation = await this.reprSideEffectService.CreateAsync(dbModel);

            if (!successfulCreation)
            {
                ModelState.AddModelError(WebConstants.StatusMessage, WebConstants.SideEffectNameExists);
                model.SideEffectGroups = await this.populator.GetSideEffectGroups();

                model.Drugs = await this.populator.GetDrugs();

                return(View(model));
            }

            if (model.DrugIds != null)
            {
                await this.reprSideEffectService.DrugsInSideEffect(model.DrugIds, dbModel.Id);
            }

            TempData.AddSuccessMessage($"Side effect {model.Name} successfully created.");
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(SideEffectFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.SideEffectGroups = await this.populator.GetSideEffectGroups();

                return(View(model));
            }

            var dbModel = Mapper.Map <SideEffect>(model);

            var successfulEditing = await this.reprSideEffectService.UpdateAsync(dbModel);

            if (!successfulEditing)
            {
                ModelState.AddModelError(WebConstants.StatusMessage, WebConstants.SideEffectNameExists);
                model.SideEffectGroups = await this.populator.GetSideEffectGroups();

                return(View(model));
            }

            TempData.AddSuccessMessage($"Side effect {model.Name} successfully updated.");
            return(RedirectToAction(nameof(Index)));
        }