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); }
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); }
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; }
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; }
public ActionResult Save(SpecialityViewModel editedModel) { var mappedModel = AutoMapper.Mapper.Map<Speciality>(editedModel); var result = specialityManager.TrySave(mappedModel); return Json(result); }