Esempio n. 1
0
        //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 "حصل خطاء أثنائء عملية الإضافة";
            }
        }
Esempio n. 2
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));
            }
        }