Esempio n. 1
0
        /// <summary>
        /// Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>ActionResult.</returns>
        public ActionResult Edit(int id)
        {
            var model = new DrugViewModel();
            model.DrugCategories = HealthHelper.GetAllDrugCategories();
            model.ActiveComponents = HealthHelper.GetAllActiveComponents();

            if (id != -1)
            {
                var svc = new DrugAppService();
                var o = svc.GetDrug(id);

                model.DrugId = o.DrugId;
                model.Name = o.Name;
                model.DrugSubCategoryId = o.DrugSubCategoryId;
                model.DrugCategoryId = o.DrugSubCategory.DrugCategoryId;
                model.ActiveComponentId = o.ActiveComponentId;
                model.IsActive = o.IsActive;

            }
            else
            {
                model.Action = "-1";
                model.DrugId = -1;
                model.Name = string.Empty;
                model.DrugCategoryId = -1;
                model.ActiveComponentId = -1;
            }



            return View(model);
        }
Esempio n. 2
0
        public ActionResult Edit(DrugViewModel model)
        {

            model.DrugCategories = HealthHelper.GetAllDrugCategories();
            model.ActiveComponents = HealthHelper.GetAllActiveComponents();

         

            try
            {
                var svc = new DrugAppService();

                var o = new Drug
                {
                    DrugId = model.DrugId,
                    Name = model.Name,
                    DrugSubCategoryId = model.DrugSubCategoryId,
                    ActiveComponentId = model.ActiveComponentId,
                    IsActive = model.IsActive

                };

                if (model.Action == "-1")
                {
                    var exist = svc.GetDrug(model.DrugId) != null;
                    if (!exist)
                    {
                        svc.AddDrug(o);
                        ViewBag.Feed = 0;
                    }
                    else
                    {
                        model.Action = "-1";
                        ViewBag.Feed = 3;
                        return View(model);
                    }
                }
                else
                {
                    o.DrugId = model.DrugId;
                    if (model.IsDeleteAction == 0)
                    {

                        svc.SaveDrug(o);
                    }
                    else
                    {
                        svc.RemoveDrug(model.DrugId);
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }

            return View(model);
        }