Ejemplo n.º 1
0
 public static Conduct ToModel(this conduct row)
 {
     return(new Conduct()
     {
         id = row.id,
         name = row.name,
         min = row.min,
         max = row.max,
         isdemerit = row.isdemerit
     });
 }
Ejemplo n.º 2
0
        public ActionResult Save(int?id, string name, bool isdemerit, short?min, short?max)
        {
            // if min/max specified then both needs to be specified
            if ((min.HasValue && !max.HasValue) ||
                (!min.HasValue && max.HasValue))
            {
                return(Json("Min and max values must be specified together".ToJsonFail()));
            }

            if (min.HasValue && max.HasValue)
            {
                if (min.Value >= max.Value)
                {
                    return(Json("Min value has to be less than Max value".ToJsonFail()));
                }
            }

            var single = new conduct();

            if (id.HasValue)
            {
                single = db.conducts.Single(x => x.id == id.Value);
            }
            single.name      = name;
            single.isdemerit = isdemerit;
            single.min       = min;
            single.max       = max;

            if (!id.HasValue)
            {
                db.conducts.InsertOnSubmit(single);
            }

            try
            {
                repository.Save();
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            var viewmodel = "Entry saved successfully".ToJsonOKMessage();

            viewmodel.data = this.RenderViewToString("AdminContent", new[] { single.ToModel() });

            return(Json(viewmodel));
        }