示例#1
0
        public JsonResult Add([FromBody] INVCO_Areas row)
        {
            row.Compania    = 1;
            row.INVCOAreaId = (db.INVCO_Areas.Max((p) => (int?)p.INVCOAreaId) ?? 0) + 1;
            db.Entry(row).Property("Fuente").CurrentValue           = "CP27730";
            db.Entry(row).Property("Fecha_Computador").CurrentValue = DateTime.Now;
            db.Entry(row).Property("Usuario").CurrentValue          = HttpContext.User.Identity.Name;

            db.INVCO_Areas.Add(row);

            if (IsValid(row))
            {
                db.SaveChanges();
            }
            else
            {
                var errMsg = "<br>" + string.Join("<br>", ModelState.Values
                                                  .SelectMany(x => x.Errors)
                                                  .Select(x => x.ErrorMessage));
                throw new Exception(errMsg);
            }
            return(Json(row));
        }
示例#2
0
        public JsonResult Update([FromBody] INVCO_Areas urow)
        {
            var row = db.Get_INVCO_Areas(urow);

            row.INVCOAreaDescripcion = urow.INVCOAreaDescripcion;
            row.INVCOAreaEstado      = urow.INVCOAreaEstado;

            db.Entry(row).Property("Fuente").CurrentValue           = "CP27730";
            db.Entry(row).Property("Fecha_Computador").CurrentValue = DateTime.Now;
            db.Entry(row).Property("Usuario").CurrentValue          = HttpContext.User.Identity.Name;

            if (IsValid(row))
            {
                db.SaveChanges();
            }
            else
            {
                var errMsg = "<br>" + string.Join("<br>", ModelState.Values
                                                  .SelectMany(x => x.Errors)
                                                  .Select(x => x.ErrorMessage));
                throw new Exception(errMsg);
            }
            return(Json(row));
        }
示例#3
0
 private bool IsValid(INVCO_Areas row)
 {
     return(ModelState.IsValid);
 }