public JsonResult remove(int id = 0)
 {
     try
     {
         RDChannel model = db.RDChannels.Find(id);
         if (model != null)
         {
             BoolString validation = model.BeforeDelete(db);
             if (validation.BoolValue)
             {
                 return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet));
             }
             db.RDChannels.Remove(model);
             db.SaveChanges();
             validation = model.AfterDelete(db);
             if (validation.BoolValue)
             {
                 return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet));
             }
             return(Json(new { id = model.id, MessageSucess = "That Channel deleted successfully." }, JsonRequestBehavior.AllowGet));
         }
         return(Json(new { Message = "This record no longer exists" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Channel") }, JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult get(int id)
        {
            RDChannel model = db.RDChannels.Find(id);

            if (model != null)
            {
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Message = "This record no longer exists" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult update(int id, RDChannel 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 Channel saved successfully." }));
        }
        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 ActionResult Form(int id = 0, string from = "")
 {
     ViewBag.relations = db.VWISRElations.Where(d => d.PK_Table == "RDChannel").ToList();
     ViewBag.from      = from;
     if (id == 0)
     {
         return(PartialView(new RDChannel()
         {
             active = true, creationDate = DateTime.Now
         }));
     }
     else
     {
         RDChannel model = db.RDChannels.Find(id);
         return(PartialView(model));
     }
 }
        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") }));
            }
        }