コード例 #1
0
ファイル: articleController.cs プロジェクト: Tabook22/MecOman
        //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 "حصل خطاء أثنائء عملية الإضافة";
            }
        }
コード例 #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 "حصل خطاء أثنائء عملية الإضافة";
            }
        }
コード例 #3
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));
            }
        }
コード例 #4
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));
        }
コード例 #5
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));
            }
        }
コード例 #6
0
ファイル: articleController.cs プロジェクト: Tabook22/MecOman
        // 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));
            }
        }
コード例 #7
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 }
            });
        }
コード例 #8
0
ファイル: articleController.cs プロジェクト: Tabook22/MecOman
        //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));
            }
        }
コード例 #9
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));
     }
 }