示例#1
0
        public ActionResult EditMeasurementType(UpdateMeasurementTypeViewModel model)
        {
            EtronixValidation EV = new EtronixValidation();
            int    alert         = -1;
            string vMessage      = null;

            Entities _contextEntities = new Entities();

            //check if all fields are correctly filled with data - data validation
            if (ModelState.IsValid)
            {
                //UpdateMeasurementTypeViewModel vUpdateMeasurementTypeViewModel = new UpdateMeasurementTypeViewModel();

                try
                {
                    _contextEntities = new Entities();
                    var vUserParameter1 = new SqlParameter("@MUID", model.Id);
                    var vUserParameter2 = new SqlParameter("@MUType", model.NewType);
                    var vResult         = _contextEntities.Database.SqlQuery <List <string> >(
                        "UpdateMeasurementType " +
                        "@MUID, " +
                        "@MUType",
                        vUserParameter1,
                        vUserParameter2).SingleOrDefault();

                    alert             = (int)EtronixValidationCode.ValidationCodeEnum.alert_success;
                    vMessage          = "The Measurement Unit was updated";
                    EV.ValidationCode = EtronixValidationCode.ValidationDic[alert];
                    EV.AddToList(vMessage);
                    model.EtronixValidation = EV;
                }
                catch (Exception exception)
                {
                    //Console.WriteLine(exception.Message);
                    alert             = (int)EtronixValidationCode.ValidationCodeEnum.alert_danger;
                    vMessage          = exception.Message + Environment.NewLine;
                    EV.ValidationCode = EtronixValidationCode.ValidationDic[alert];
                    EV.AddToList(vMessage);
                    model.EtronixValidation = EV;
                }
            }

            else
            {
                List <string> mE = ModelState.Values.SelectMany(x => x.Errors).Select(e => e.ErrorMessage).ToList();
                alert             = (int)EtronixValidationCode.ValidationCodeEnum.alert_danger;
                EV.ValidationCode = EtronixValidationCode.ValidationDic[alert];
                foreach (var msg in mE)
                {
                    EV.AddToList(msg);
                }
                model.EtronixValidation = EV;
                return(View(model));
            }



            return(View(model));
        }
示例#2
0
        public ActionResult EditMeasurementType(string MUID)
        {
            EtronixValidation EV = new EtronixValidation();
            int      alert       = -1;
            string   vMessage    = null;
            Entities _contextEntities;

            UpdateMeasurementTypeViewModel vUpdateMeasurementTypeViewModel = new UpdateMeasurementTypeViewModel();



            try
            {
                _contextEntities = new Entities();
                var vParameter = new SqlParameter("@MUID", MUID);
                Procedures.MeasurementUnitTypes vMeasurementType =
                    _contextEntities.Database.SqlQuery <Procedures.MeasurementUnitTypes>(
                        "GetMeasurementType " + "@MUID ",
                        vParameter).SingleOrDefault();

                vUpdateMeasurementTypeViewModel.Id                = vMeasurementType.Id.ToString();
                vUpdateMeasurementTypeViewModel.Type              = vMeasurementType.Type;
                vUpdateMeasurementTypeViewModel.NewType           = "";
                vUpdateMeasurementTypeViewModel.EtronixValidation = EV;
            }
            catch (Exception exception)
            {
                //Console.WriteLine(exception.Message);
                alert             = (int)EtronixValidationCode.ValidationCodeEnum.alert_danger;
                vMessage          = exception.Message + Environment.NewLine;
                EV.ValidationCode = EtronixValidationCode.ValidationDic[alert];
                EV.AddToList(vMessage);
                vUpdateMeasurementTypeViewModel.EtronixValidation = EV;
            }


            return(View(vUpdateMeasurementTypeViewModel));
        }