public async Task <LocationServiceModel> GetByIdAsync(string id) { Location location = await this._context.Locations.FindAsync(id); LocationServiceModel serviceModel = this.MapToServiceModel(location); return(serviceModel); }
public async Task <LocationServiceModel> UpdateAsync(LocationServiceModel entity, string issuerrId, bool isUser = true) { Location location = this.MapToDataModel(entity); User user = this._context.Users.FirstOrDefault(x => x.Id == issuerrId); location.User = user; this._context.Update(location); await this._context.SaveChangesAsync(); return(null); }
private LocationServiceModel MapToServiceModel(Location entity) { LocationServiceModel location = new LocationServiceModel { Id = entity.Id, Adress = entity.Adress, Name = entity.Name }; return(location); }
private Location MapToDataModel(LocationServiceModel entity) { Location location = new Location { Id = entity.Id, Adress = entity.Adress, Name = entity.Name, }; return(location); }
public async Task <List <LocationServiceModel> > GetAllAsync() { List <Location> locations = this._context.Locations.ToList(); List <LocationServiceModel> serviceModels = new List <LocationServiceModel>(); foreach (var location in this._context.Locations) { LocationServiceModel locationServiceModel = this.MapToServiceModel(location); serviceModels.Add(locationServiceModel); } return(serviceModels); }
public async Task <List <LocationServiceModel> > GetAllAsyncOfUser(string userId) { List <Location> locations = this._context.Locations.Where(x => x.User.Id == userId).OrderBy(x => x.Name).ToList(); List <LocationServiceModel> serviceModels = new List <LocationServiceModel>(); foreach (var location in locations) { LocationServiceModel locationServiceModel = this.MapToServiceModel(location); locationServiceModel.UserId = userId; serviceModels.Add(locationServiceModel); } return(serviceModels); }
public async Task <IActionResult> Edit(string id, LocationServiceModel locationServiceModel) { try { string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this._locationService.UpdateAsync(locationServiceModel, userId); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <LocationServiceModel> CreateAsync(LocationServiceModel entity, string userId) { entity.Id = Guid.NewGuid().ToString(); Location location = MapToDataModel(entity); User user = this._context.Users.FirstOrDefault(x => x.Id == userId); location.User = user; await this._context.AddAsync(location); await this._context.SaveChangesAsync(); return(null); }
public async Task <IActionResult> Delete(string id, LocationServiceModel locationServiceModel) { try { await this._locationService.DeleteAsync(id); return(RedirectToAction(nameof(Index))); } catch (LocationHasTasksException ex) { TempData["TheErrorHappendWhen"] = "deleteing"; TempData["Entity"] = "location"; TempData["ExceptionMessage"] = ex.Message; return(RedirectToAction("CRUDError", "Error")); } catch { return(View()); } }
// GET: LocationController/Delete/5 public async Task <IActionResult> Delete(string id) { LocationServiceModel locationServiceModel = await this._locationService.GetByIdAsync(id); return(View(locationServiceModel)); }