Exemplo n.º 1
0
 public ActionResult EditSpeciality(SpecialityViewModel editedModel)
 {
     var mappedModel = AutoMapper.Mapper.Map<Speciality>(editedModel);
     var result = specialityManager.TrySave(mappedModel);
     var localizedViewModel = AutoMapper.Mapper.Map<SpecialityViewModel>((Speciality)specialityManager.GetBaseModel(mappedModel));
     return PartialView("SpecialityPartial", localizedViewModel);
 }
Exemplo n.º 2
0
        public ActionResult AddSpeciality(SpecialityViewModel viewModel)
        {
            var model = AutoMapper.Mapper.Map<Speciality>(viewModel);

            if (specialityManager.TryCreate(model))
            {
                var localizedViewModel = AutoMapper.Mapper.Map<SpecialityViewModel>((Speciality)specialityManager.GetBaseModel(model));
                return PartialView("SpecialityPartial", localizedViewModel);
            }

            return Json(false);
        }
Exemplo n.º 3
0
 public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     var model = new SpecialityViewModel();
     model.Id = bindingContext.ValueProvider.GetValue("Id").AttemptedValue;
     model.Name = bindingContext.ValueProvider.GetValue("Name").AttemptedValue;
     model.EnglishName = '"' + bindingContext.ValueProvider.GetValue("EnglishName").AttemptedValue + '"';
     var dict = new Dictionary<int, int>();
     foreach (var item in model.Salaries)
     {
         int tmp = 0;
         int.TryParse(bindingContext.ValueProvider.GetValue("Salaries[" + item.Key + "]").AttemptedValue, out tmp);
         dict[item.Key] = tmp;
     }
     model.Salaries = dict;
     return model;
 }
Exemplo n.º 4
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            int tmp = 0;
            var model = new SpecialityViewModel();
            model.Id = bindingContext.ValueProvider.GetValue("Id").AttemptedValue;
            model.Name = bindingContext.ValueProvider.GetValue("Name").AttemptedValue;
            model.EnglishName = String.Format("\"{0}\"", bindingContext.ValueProvider.GetValue("EnglishName").AttemptedValue);
            var dictionary = new Dictionary<int, int?>();
            foreach (var item in model.Salaries)
            {
                var contextValue = bindingContext.ValueProvider.GetValue("Salaries.[" + item.Key + "]");
                string val = contextValue == null ? null : contextValue.AttemptedValue;
                if(string.IsNullOrEmpty(val))
                    dictionary[item.Key] = null;
                else {
                    int.TryParse(val, out tmp);
                    dictionary[item.Key] = tmp;
                }
            }
            model.Salaries = dictionary;

            var newDictionary = new Dictionary<string, int?>();
            foreach (var item in model.Prices)
            {
                var contextValue = bindingContext.ValueProvider.GetValue("Salaries.[" + item.Key + "]");
                string val = contextValue == null ? null : contextValue.AttemptedValue;
                if (string.IsNullOrEmpty(val))
                    newDictionary[item.Key] = null;
                else
                {
                    int.TryParse(val, out tmp);
                    newDictionary[item.Key] = tmp;
                }
            }
            model.Prices = newDictionary;

            int.TryParse(bindingContext.ValueProvider.GetValue("StartOfWorking").AttemptedValue, out tmp);

            model.StartOfWorking = tmp;

            return model;
        }
Exemplo n.º 5
0
 public ActionResult Save(SpecialityViewModel editedModel)
 {
     var mappedModel = AutoMapper.Mapper.Map<Speciality>(editedModel);
     var result = specialityManager.TrySave(mappedModel);
     return Json(result);
 }