public void Create(SpotViewModel spotViewModel) { spotViewModel.State = SpotState.Active; Mapper.Initialize(cfg => cfg.CreateMap <SpotViewModel, Spot>()); using (database = new EFUnitOfWork(connectionName)) { database.Spots.Create(Mapper.Map <Spot>(spotViewModel)); database.Save(); } }
public void Update(SpotViewModel spotViewModel) { using (database = new EFUnitOfWork(connectionName)) { var mapper = AutoMapperConfigs.SpotVMToSpot.CreateMapper(); var spot = mapper.Map <Spot>(spotViewModel); using (database = new EFUnitOfWork(connectionName)) { database.Spots.Update(spot); database.Save(); } } }
public List<SpotViewModel> FindMiningSpots(Position position) { List<SpotViewModel> spots = new List<SpotViewModel>(); foreach (var item in GetSpots()) { var spotVM = new SpotViewModel(item, position.Latitude, position.Longitude); if (spotVM.Distance < 0.25) { spots.Add(spotVM); } } return spots; }
public List <SpotViewModel> FindMiningSpots(Position position) { List <SpotViewModel> spots = new List <SpotViewModel>(); foreach (var item in GetSpots()) { var spotVM = new SpotViewModel(item, position.Latitude, position.Longitude); if (spotVM.Distance < 0.25) { spots.Add(spotVM); } } return(spots); }
public IActionResult Spot(int spotid) { if (UserSession == null) { return(RedirectToAction("Index", "Login")); } ViewBag.CurrentUser = dbContext.Users.FirstOrDefault(u => u.UserId == UserSession); SpotViewModel model = new SpotViewModel() { CurrentSpot = dbContext.Spots .Include(c => c.Comments) .ThenInclude(u => u.User) .FirstOrDefault(s => s.SpotId == spotid) }; return(View("Spot", model)); }
public async Task <ActionResult> Post([FromBody] SpotViewModel newSpotViewModel) { if (ModelState.IsValid) { Spot newSpot = Mapper.Map <Spot>(newSpotViewModel); newSpot.UserName = User.Identity.Name; if (newSpot.Id == 0) { _repository.AddSpot(newSpot); } else { _repository.UpdateSpot(newSpot); } if (await _repository.SaveChangesAsync()) { return(Created($"api/spots/{newSpotViewModel.Name}", Mapper.Map <SpotViewModel>(newSpotViewModel))); } } return(BadRequest("Failed to save changes to database")); }