Exemple #1
0
        public ActionResult AssignToDepot()
        {
            var drugUnits = _drugUnitService.GetAllDrugUnits();
            var depots    = _depotService.GetAllDepots()
                            .Select(f => new SelectListItem
            {
                Value = f.Id.ToString(),
                Text  = f.Name
            });

            var viewModel = new DrugUnitAssignViewModel
            {
                DrugUnits = drugUnits
                            .Select(AutoMapper.Mapper.Map <DrugUnitViewModel>)
                            .ToList(),
                Depots = depots.ToList()
            };

            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult AssignToDepot(DrugUnitAssignViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var drugUnits = viewModel.DrugUnits
                                    .Select(AutoMapper.Mapper.Map <DrugUnit>)
                                    .ToList();
                    _drugUnitService.AssignDrugUnitToDepot(drugUnits);

                    TempData["messageOk"] = "Your changes were saved successfully";
                    return(RedirectToAction("AssignToDepot", "DrugUnit"));
                }
                catch (Exception)
                {
                    TempData["messageError"] = "An error was occurred while saving";
                }
            }
            return(View(viewModel));
        }