public JsonResult create(RDChannel model) { BoolString validation = model.BeforeSave(db); if (validation.BoolValue) { return(Json(new { Message = validation.StringValue })); } db.RDChannels.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 Channel saved successfully." })); }
public JsonResult Save(RDChannel 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; } } if (Request.Files.Count > 0) { if (Request.Files["logoImage"].ContentLength == 0) { db.Entry(model).Property(x => x.logoImage).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.RDChannels.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/RDChannel/iconImage/"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var path = Path.Combine(directory, filename); file.SaveAs(path); model.iconImage = filename; } file = Request.Files["logoImage"]; if (file != null && file.ContentLength > 0) { string ext = Path.GetExtension(file.FileName); string filename = model.id.ToString() + ext; string directory = Server.MapPath("~/files/RDChannel/logoImage/"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var path = Path.Combine(directory, filename); file.SaveAs(path); model.logoImage = filename; } } db.SaveChanges(); return(Json(new { id = model.id, MessageSucess = "That Channel saved successfully." })); } catch (Exception ex) { return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Channel") })); } }