//Add new article-----------------------------------------------------------------------------------------------------
        public JsonResult addNewArticle(Article article)
        {
            DhofarDb db       = new DhofarDb();
            artOrder artorder = new artOrder();
            string   msg      = string.Empty;

            if (article != null)
            {
                //article.post_adate = DateTime.Parse(DateTime.Now.ToShortTimeString());
                db.Articles.Add(article);
                db.SaveChanges();

                // return Json(new { status = "تمت عملية الإضافة بنجاح" }, JsonRequestBehavior.AllowGet);
                msg = "تمت عملية الإضافة بنجاح";

                //get the current added article, by getting the max articleid, then using that id to get the whole article
                // int maxArtId = db.Articles.Max(x => x.ArticleId);
                //int artid = article.ArticleId;
                //var maxOrder = db.Articles.Where(x=>x.Location  == article.Location).Max(x => x.order );
                //Article getArt = db.Articles.Where(x => x.ArticleId == maxArtId).FirstOrDefault();

                //change the articles order based on the current article order
                // artorder.getOrder(getArt.ArticleId, getArt.order, getArt.Location, maxOrder);

                return(Json(msg, JsonRequestBehavior.AllowGet));
                //return "تمت عملية الإضافة";
            }
            else
            {
                msg = "حصل خطاء أثناء عملية الإضافة";
                return(Json(msg, JsonRequestBehavior.AllowGet));
                // return "حصل خطاء أثنائء عملية الإضافة";
            }
        }
Exemple #2
0
        //Adding post data

        public JsonResult addNewPost(Post post)
        {
            string msg = string.Empty;

            if (post != null)
            {
                using (DhofarDb Obj = new DhofarDb())
                {
                    post.post_adate = DateTime.Parse(DateTime.Now.ToShortTimeString());
                    Obj.Posts.Add(post);
                    Obj.SaveChanges();

                    // return Json(new { status = "تمت عملية الإضافة بنجاح" }, JsonRequestBehavior.AllowGet);
                    msg = "تمت عملية الإضافة بنجاح";
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                    //return "تمت عملية الإضافة";
                }
            }
            else
            {
                msg = "حصل خطاء أثناء عملية الإضافة";
                return(Json(msg, JsonRequestBehavior.AllowGet));
                // return "حصل خطاء أثنائء عملية الإضافة";
            }
        }
        // Get Article by Id
        public JsonResult getArticleById(string id)
        {
            int aid = Convert.ToInt32(id);

            using (DhofarDb db = new DhofarDb())
            {
                var art = (from a in db.Articles
                           join b in db.Posts on a.PostId equals b.PostId
                           where a.ArticleId == aid
                           select new
                {
                    a.ArticleId,
                    a.Location,
                    a.PostId,
                    a.order,
                    b.post_title,
                    b.post_status,
                    b.post_adate,
                    b.post_img
                }).FirstOrDefault();
                //Article art = db.Articles.Where(x => x.ArticleId == aid).FirstOrDefault();

                return(Json(art, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #4
0
        //Delete Images
        public JsonResult delImgs(string id)
        {
            int    imgId = Convert.ToInt32(id);
            string msg   = string.Empty;

            using (DhofarDb db = new DhofarDb())
            {
                UploadedFile up        = db.UploadedFiles.Where(x => x.FileId == imgId).FirstOrDefault();
                string       file_name = up.FileName;
                db.UploadedFiles.Remove(up);
                db.SaveChanges();

                //delete image from uploadfiles folder
                string   path = Server.MapPath("~/UploadedFiles/" + file_name);
                FileInfo file = new FileInfo(path);
                if (file.Exists)//check file exsit or not
                {
                    file.Delete();
                }
                else
                {
                }

                msg = " تم حذف الصورة بنجاح";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #5
0
        //Get Post By Id
        public JsonResult getPostById(string id)
        {
            int      pid = Convert.ToInt32(id);
            DhofarDb db  = new DhofarDb();
            Post     pst = db.Posts.Where(x => x.PostId == pid).FirstOrDefault();

            return(Json(pst, JsonRequestBehavior.AllowGet));
        }
Exemple #6
0
        public JsonResult getPostsLst()
        {
            DhofarDb    db         = new DhofarDb();
            List <Post> lst        = db.Posts.OrderByDescending(x => x.PostId).ToList();
            int         totalPosts = lst.Count();

            return(Json(new { pstLst = lst, totalPst = totalPosts }, JsonRequestBehavior.AllowGet));
        }
 //Get all posts, which will be used inside the articles--------------------------------------------------------------
 public JsonResult getAllPosts()
 {
     using (DhofarDb db = new DhofarDb())
     {
         List <Post> lstPst = db.Posts.Select(x => x).ToList();
         return(Json(lstPst, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #8
0
 //get all images
 public JsonResult getAllImg()
 {
     using (DhofarDb db = new DhofarDb())
     {
         List <UploadedFile> uf = db.UploadedFiles.Select(x => x).ToList();
         return(Json(uf, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #9
0
        //Delete Posts
        public JsonResult delPost(string id)
        {
            DhofarDb db    = new DhofarDb();
            int      getId = Convert.ToInt32(id);
            Post     pst   = db.Posts.Where(p => p.PostId == getId).FirstOrDefault();

            db.Posts.Remove(pst);
            db.SaveChanges();
            string msg = "تم حذف المقال بنجاح";

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Exemple #10
0
        public ActionResult SaveUploadedFile()
        {
            bool   isSavedSuccessfully = true;
            string msg   = string.Empty;
            string fName = "";

            try
            {
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    fName = file.FileName;
                    if (file != null && file.ContentLength > 0)
                    {
                        int size = file.ContentLength;

                        var    path       = Path.Combine(Server.MapPath("~/UploadedFiles"));
                        string pathString = System.IO.Path.Combine(path.ToString());
                        //var fileName1 = Path.GetFileName(file.FileName);
                        var  fileName1 = Guid.NewGuid() + Path.GetExtension(file.FileName);
                        bool isExists  = System.IO.Directory.Exists(pathString);
                        if (!isExists)
                        {
                            System.IO.Directory.CreateDirectory(pathString);
                        }
                        var uploadpath = string.Format("{0}\\{1}", pathString, fileName1);
                        file.SaveAs(uploadpath);
                        using (DhofarDb db = new DhofarDb())
                        {
                            UploadedFile uf = new UploadedFile();
                            uf.FileName = fileName1;
                            uf.FileSize = size;
                            db.UploadedFiles.Add(uf);
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isSavedSuccessfully = false;
            }
            if (isSavedSuccessfully)
            {
                msg = "تم رفعل الصورة بنجاح";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            else
            {
                msg = "حصل خطاء أثناء رفع الصورة";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #11
0
        // Delete article
        public JsonResult delArticle(string id)
        {
            string msg = string.Empty;
            int    aid = Convert.ToInt32(id);

            using (DhofarDb db = new DhofarDb())
            {
                Article art = db.Articles.Where(x => x.ArticleId == aid).FirstOrDefault();
                db.Articles.Remove(art);
                db.SaveChanges();

                msg = "لقد تم حذف المفالة بنجاح";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #12
0
        public JsonResult SaveFiles(string description)
        {
            string Message, fileName, actualFileName;

            Message = fileName = actualFileName = string.Empty;
            bool flag = false;

            if (Request.Files != null)
            {
                var file = Request.Files[0];
                actualFileName = file.FileName;
                fileName       = Guid.NewGuid() + Path.GetExtension(file.FileName);
                int size = file.ContentLength;

                try
                {
                    file.SaveAs(Path.Combine(Server.MapPath("~/UploadedFiles"), fileName));

                    UploadedFile f = new UploadedFile
                    {
                        FileName    = actualFileName,
                        FilePath    = fileName,
                        Description = description,
                        FileSize    = size
                    };
                    using (DhofarDb dc = new DhofarDb())
                    {
                        dc.UploadedFiles.Add(f);
                        dc.SaveChanges();
                        Message = "File uploaded successfully";
                        flag    = true;
                    }
                }
                catch (Exception)
                {
                    Message = "File upload failed! Please try again";
                }
            }
            return(new JsonResult {
                Data = new { Message = Message, Status = flag }
            });
        }
Exemple #13
0
        //getting all the articles in the news category to be displyied inside the homepage
        public JsonResult allNewsForHome()
        {
            DhofarDb db = new DhofarDb();

            var art = (from a in db.Articles
                       join b in db.Posts on a.PostId equals b.PostId
                       where a.Location == "قائمة الأخبار"
                       select new
            {
                a.ArticleId,
                a.Location,
                a.PostId,
                a.order,
                b.post_title,
                b.post_status,
                b.post_adate,
                b.post_img
            }).ToList();

            //Article art = db.Articles.Where(x => x.ArticleId == aid).FirstOrDefault();
            return(Json(art, JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        //get all the articles-----------------------------------------------------------------------------------------------
        public JsonResult getAllArtciles()
        {
            //here we are going to merge two tables articles and posts then pass the result to a view model vmartposts
            using (DhofarDb db = new DhofarDb())
            {
                var getlst = db.Articles.
                             Join(db.Posts,
                                  a => a.PostId, b => b.PostId,
                                  (a, b) => new VMArtPost
                {
                    ArticleId   = a.ArticleId,
                    Location    = a.Location,
                    PostId      = a.PostId,
                    order       = a.order,
                    post_title  = b.post_title,
                    post_status = b.post_status,
                    post_adate  = b.post_adate,
                    post_img    = b.post_img
                }).ToList();

                return(Json(getlst.OrderByDescending(x => x.ArticleId), JsonRequestBehavior.AllowGet));
            }
        }
Exemple #15
0
        //edit article -----------------------------------------------------------------------------------------------------------
        public JsonResult editArticle(Article article)
        {
            DhofarDb db       = new DhofarDb();
            artOrder artorder = new artOrder();
            string   msg      = string.Empty;

            if (article != null)
            {
                int     aid = Convert.ToInt32(article.ArticleId);
                Article art = db.Articles.Where(x => x.ArticleId == aid).FirstOrDefault();
                art.Location = article.Location;
                art.Status   = article.Status;
                art.SDate    = article.SDate;
                art.EDate    = article.EDate;
                art.PostId   = article.PostId;
                art.order    = article.order;
                //article.post_adate = DateTime.Parse(DateTime.Now.ToShortTimeString());
                // db.Articles.Add(art);
                db.SaveChanges();

                // return Json(new { status = "تمت عملية الإضافة بنجاح" }, JsonRequestBehavior.AllowGet);
                msg = "تمت عملية الإضافة بنجاح";

                //get the current updated article
                // Article getArt = db.Articles.Where(x => x.ArticleId == aid).FirstOrDefault();
                //var maxOrder = db.Articles.Where(x => x.Location == article.Location).Max(x => x.order);
                //change the articles order based on the current article order
                // artorder.getOrder(getArt.ArticleId, getArt.order, getArt.Location, maxOrder);

                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            else
            {
                msg = "حصل خطاء أثناء عملية الإضافة";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #16
0
 //Update post
 public JsonResult updatePost(Post post)
 {
     if (post != null)
     {
         using (DhofarDb db = new DhofarDb())
         {
             int no       = Convert.ToInt32(post.PostId);
             var postList = db.Posts.Where(x => x.PostId == no).FirstOrDefault();
             postList.post_title     = post.post_title;
             postList.post_data      = post.post_data;
             postList.post_img       = post.post_img;
             postList.post_img_title = post.post_img_title;
             postList.post_status    = post.post_status;
             db.SaveChanges();
             string msg = "حتمت عملية الإضافة";
             return(Json(msg, JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         string msg = "حدثت مشكلة في تعديل البيانات";
         return(Json(msg, JsonRequestBehavior.AllowGet));
     }
 }