예제 #1
0
 public ActionResult Add(VmBlogAdd model)
 {
     if (ModelState.IsValid)
     {
         var userid          = HttpContext.Request.GetOwinContext().Request.User.Identity.GetUserId();
         var loggedInDonorId = appDbContext.Users.FirstOrDefault(f => f.Id == userid).ReferrenceId ?? 0;
         #region Image Upload
         var uri = Request.Url.Host;
         System.IO.Directory.CreateDirectory(Server.MapPath("~/Images/Blog/" + loggedInDonorId + "/" + uri));
         string path = "";
         if (model.Image != null)
         {
             string pic          = System.IO.Path.GetFileName(model.Image.FileName);
             string physicalPath =
                 System.IO.Path.Combine(Server.MapPath("~/Images/Blog/" + loggedInDonorId + "/" + uri), pic);
             path = "/Images/Blog/" + loggedInDonorId + "/" + uri + "/" + pic;
             model.Image.SaveAs(physicalPath);
             model.ImageUrl = path;
         }
         #endregion
         BlogService blogService = new BlogService(db);
         int         blogId      = 0;
         blogService.Add(model, loggedInDonorId, out blogId);
     }
     //return Json(JsonRequestBehavior.AllowGet);
     return(RedirectToAction("Index", "Home"));
 }
예제 #2
0
 public ActionResult Add(VmBlogAdd model)
 {
     if (ModelState.IsValid)
     {
         var         userid          = HttpContext.Request.GetOwinContext().Request.User.Identity.GetUserId();
         var         loggedInDonorId = appDbContext.Users.FirstOrDefault(f => f.Id == userid).ReferrenceId ?? 0;
         BlogService blogService     = new BlogService(db);
         int         blogId          = 0;
         blogService.Add(model, loggedInDonorId, out blogId);
     }
     return(Json(JsonRequestBehavior.AllowGet));
 }
예제 #3
0
        public int Add(VmBlogAdd vmBlog, int loggedInDonorId, out int blogId)
        {
            var isSaved = 0;

            if (vmBlog.BlogHeaderId > 0)
            {
                var data = db.Blog.Where(w => w.Attribute1 != "feedback" && w.BlogId == vmBlog.BlogHeaderId).FirstOrDefault();
                data.Heading = vmBlog.BlogTitle;
                data.Details = vmBlog.Description;
                if (vmBlog.ImageUrl != null)
                {
                    data.ImageUrl = vmBlog.ImageUrl;
                }
                if (vmBlog.IsFeedback)
                {
                    data.Attribute1 = "feedback";
                }
                data.BloodDonorHeaderId = loggedInDonorId;
                data.LastUpdateDate     = DateTime.Now;
                isSaved = db.SaveChanges();
                blogId  = data.BlogId;
            }
            else
            {
                var data = new Blog();
                data.Heading            = vmBlog.BlogTitle;
                data.Details            = vmBlog.Description;
                data.ImageUrl           = vmBlog.ImageUrl;
                data.BloodDonorHeaderId = loggedInDonorId;
                if (vmBlog.IsFeedback)
                {
                    data.Attribute1 = "feedback";
                }
                data.CreationDate = DateTime.Now;
                db.Blog.Add(data);
                isSaved = db.SaveChanges();
                blogId  = data.BlogId;
            }
            return(isSaved);
        }