예제 #1
0
 public ActionResult Create(EthnicityViewModel vm)
 {
     if (this.personTasks.GetEthnicity(vm.EthnicityName) != null)
     {
         ModelState.AddModelError("EthnicityName", "Ethnicity name already exists.");
     }
     if (ModelState.IsValid)
     {
         Ethnicity ethnicity = Mapper.Map(vm, new Ethnicity());
         ethnicity = this.personTasks.SaveEthnicity(ethnicity);
         return(RedirectToAction("Details", new { id = ethnicity.Id }));
     }
     return(Create());
 }
        /// <summary>
        /// To the view model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static EthnicityViewModel ToViewModel(this EthnicityModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new EthnicityViewModel
            {
                EthnicityID = model.EthnicityID,
                Ethnicity   = model.Ethnicity
            };

            return(entity);
        }
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static EthnicityModel ToModel(this EthnicityViewModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new EthnicityModel
            {
                EthnicityID = entity.EthnicityID,
                Ethnicity   = entity.Ethnicity
            };

            return(model);
        }
예제 #4
0
        public ActionResult Edit(EthnicityViewModel vm)
        {
            Ethnicity ethnicity    = this.personTasks.GetEthnicity(vm.Id);
            Ethnicity newEthnicity = this.personTasks.GetEthnicity(vm.EthnicityName);

            if (ethnicity != null && newEthnicity != null && newEthnicity.Id != ethnicity.Id)
            {
                ModelState.AddModelError("EthnicityName", "Ethnicity name already exists.");
            }

            Ethnicity e = this.personTasks.GetEthnicity(vm.Id);

            if (ModelState.IsValid)
            {
                e = Mapper.Map(vm, e);
                return(RedirectToAction("Details", new { id = vm.Id }));
            }
            return(Edit(vm.Id));
        }
예제 #5
0
        public ActionResult Create()
        {
            EthnicityViewModel vm = new EthnicityViewModel();

            return(View(vm));
        }