public ActionResult AddEditMeasureUnit(Int32?MeasureUnitId)
        {
            var model = new AddEditMeasureUnitViewModel();

            model.Fill(CargarDatosContext(), MeasureUnitId);
            return(View(model));
        }
        public ActionResult AddEditMeasureUnit(AddEditMeasureUnitViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    model.Fill(CargarDatosContext(), model.MeasureUnitId);
                    TryUpdateModel(model);
                    PostMessage(MessageType.Error);
                    return(View(model));
                }

                MeasureUnit measureUnit = null;

                if (model.MeasureUnitId.HasValue)
                {
                    measureUnit = context.MeasureUnit.FirstOrDefault(x => x.MeasureUnitId == model.MeasureUnitId);
                }
                else
                {
                    measureUnit       = new MeasureUnit();
                    measureUnit.State = ConstantHelpers.ESTADO.ACTIVO;
                    context.MeasureUnit.Add(measureUnit);
                }

                measureUnit.Description = model.Description;
                measureUnit.Acronym     = model.Acronym;

                context.SaveChanges();
                PostMessage(MessageType.Success);

                return(RedirectToAction("ListMeasureUnit"));
            }
            catch (Exception ex)
            {
                PostMessage(MessageType.Error);
                model.Fill(CargarDatosContext(), model.MeasureUnitId);

                return(View(model));
            }
        }