예제 #1
0
        public JsonResult update(int id, RDClient model)
        {
            BoolString validation = model.BeforeEdit(db);

            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            validation = model.AfterEdit(db);
            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            return(Json(new { id = model.id, MessageSucess = "That Client saved successfully." }));
        }
예제 #2
0
        public JsonResult Save(RDClient model, FormCollection form)
        {
            try
            {
                if (model.id != 0)
                {
                    BoolString validation = model.BeforeEdit(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                    validation            = model.BeforeSave(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    validation = model.BeforeEdit(db);

                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    db.SaveChanges();
                    validation = model.AfterSave(db);

                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    validation = model.AfterEdit(db);

                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                }
                else
                {
                    BoolString validation = model.BeforeSave(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    validation = model.BeforeCreate(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }

                    db.RDClients.Add(model);
                    db.SaveChanges();
                    validation = model.AfterSave(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    validation = model.AfterCreate(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                }
                return(Json(new { id = model.id, MessageSucess = "That Client saved successfully." }));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Client") }));
            }
        }