Example #1
0
 public ActionResult Create(Document collection)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var session = (THPDocument.Common.UserLogin)Session[THPDocument.Common.CommonConstants.USER_SESSION];
             //collection.PostBy = id;
             byte[]             imageData = null;
             HttpPostedFileBase poImgFile = Request.Files["fileim"];
             HttpPostedFileBase fiFile    = Request.Files["filefi"];
             if (poImgFile != null && poImgFile.ContentLength > 0)
             {
                 using (var binary = new BinaryReader(poImgFile.InputStream))
                 {
                     imageData = binary.ReadBytes(poImgFile.ContentLength);
                 }
             }
             if (fiFile.ContentLength > 0)
             {
                 string _FileName = Path.GetFileName(fiFile.FileName);
                 string _path     = Path.Combine(Server.MapPath("~/Content/Files"), _FileName);
                 fiFile.SaveAs(_path);
             }
             collection.DocumentFile = fiFile.FileName;
             collection.Thumbnail    = imageData;
             collection.Status       = false;
             collection.Rate         = 5;
             collection.DatePost     = DateTime.Now;
             collection.PostBy       = session.ID;
             var res   = dd.InsertDocument(collection);
             int?point = session.Point + 50;
             dd.AddPoint(point, session.ID);
             if (res > 0)
             {
                 return(RedirectToAction("PostSuccess", "Document"));
             }
             else
             {
                 ModelState.AddModelError("", "Upload failed");
             }
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }