Пример #1
0
        public JsonResult create(RDProgramming model)
        {
            BoolString validation = model.BeforeSave(db);

            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            db.RDProgrammings.Add(model);
            db.SaveChanges();
            validation = model.AfterSave(db);
            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            return(Json(new { id = model.id, MessageSucess = "That Programming saved successfully." }));
        }
Пример #2
0
        public JsonResult Save(RDProgramming 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;
                    if (Request.Files.Count > 0)
                    {
                        if (Request.Files["iconImage"].ContentLength == 0)
                        {
                            db.Entry(model).Property(x => x.iconImage).IsModified = false;
                        }
                    }
                    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.RDProgrammings.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 }));
                    }
                }
                HttpPostedFileBase file = null;
                if (Request.Files.Count > 0)
                {
                    file = Request.Files["iconImage"];
                    if (file != null && file.ContentLength > 0)
                    {
                        string ext       = Path.GetExtension(file.FileName);
                        string filename  = model.id.ToString() + ext;
                        string directory = Server.MapPath("~/files/RDProgramming/iconImage/");
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        var path = Path.Combine(directory, filename);
                        file.SaveAs(path);
                        model.iconImage = filename;
                    }
                }
                db.SaveChanges();
                return(Json(new { id = model.id, MessageSucess = "That Programming saved successfully." }));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Programming") }));
            }
        }