public ActionResult Create(CreatePlaceViewModel model) { try { if (ModelState.IsValid) { placeModel.Create(model); return RedirectToAction("Index"); } return View(placeModel.GetCountriesForCreate()); } catch { return View(placeModel.GetCountriesForCreate()); } }
public void Create(CreatePlaceViewModel model) { var userModel = new UserModel(); using (var db = new DBEntitiesProxy()) { var userid = userModel.GetUserID(model.UserEmail); db.Place.Add(new Place() { Name = model.Name, Content = model.Content, Photo_URI = model.Photo_URI, CountryId = model.CountryId, IsAccepted = false, UserId = userid, AddDate = System.DateTime.Now, Ranking = 1, ContentPL = model.ContentPL, ContentPT = model.ContentPT, }); db.SaveChanges(); } }
public CreatePlaceViewModel GetCountriesForCreate() { CreatePlaceViewModel model = new CreatePlaceViewModel(); model.Countries = new List<CountryModel>(); using (var db = new DBEntitiesProxy()) { model.Countries = db.Country.Select(x => new CountryModel { Code = x.Code, CountryId = x.CountryId, Name = x.Name }).ToList(); } return model; }
public CreatePlacePage() { InitializeComponent(); BindingContext = new CreatePlaceViewModel(); }