using OhMyGlobeProject.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace OhMyGlobeProject.Controllers | |
{ | |
public class GeoPostController : Controller | |
{ | |
private ApplicationDbContext db = new ApplicationDbContext(); | |
public ActionResult GetPost(int ID) | |
{ | |
var model = db.GeoPosts.FirstOrDefault(x => x.ID == ID); | |
return Json(new { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); | |
} | |
[HttpPost] | |
public ActionResult CreatePost(GeoPost newPost) | |
{ | |
string message = ""; | |
bool isSuccess = false; | |
try | |
{ | |
var files = Request.Files; | |
db.GeoPosts.Add(newPost); | |
foreach (var item in files) | |
{ | |
var path = CommonLogic.UploadPhoto((HttpPostedFileBase)item); | |
if (!String.IsNullOrWhiteSpace(path)) | |
{ | |
db.GeoPostsImagePaths.Add(new GeoPostImagePaths { Post = newPost, FilePath = path }); | |
} | |
} | |
db.SaveChanges(); | |
isSuccess = true; | |
} | |
catch(Exception ex) | |
{ | |
message = ex.Message; | |
} | |
return Json(new{ isSuccess = isSuccess, message }); | |
} | |
public ActionResult GetPostComment(int GeoPost_ID) | |
{ | |
var model = db.GeoPosts.Where(x => x.ID == GeoPost_ID).ToList(); | |
return Json(new { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); | |
} | |
[HttpPost] | |
public ActionResult CreatePostComment(GeoPostComments newPostComment) | |
{ | |
string message = ""; | |
bool isSuccess = false; | |
try | |
{ | |
db.GeoPostsComments.Add(newPostComment); | |
db.SaveChanges(); | |
isSuccess = true; | |
} | |
catch (Exception ex) | |
{ | |
message = ex.Message; | |
} | |
return Json(new { isSuccess = isSuccess, message }); | |
} | |
} | |
} |
Вчера наша команда получила очень неоднозначные отзывы от менторов. Сегодня мы решили прислушаться к сказанному. Работы много и очень разной, но желание завершить прототип придаёт сил.
SpaceApps is a NASA incubator innovation program.