public EstablishmentLocationResponse ToEstablishmentLocationResponse(EstablishmentLocationEntity establishmentLocationEntity) { return(new EstablishmentLocationResponse { Id = establishmentLocationEntity.Id, Remarks = establishmentLocationEntity.Remarks, SourceLatitude = establishmentLocationEntity.SourceLatitude, TargetLatitude = establishmentLocationEntity.TargetLatitude, SourceLongitude = establishmentLocationEntity.SourceLatitude, TargetLongitude = establishmentLocationEntity.TargetLongitude, Establishments = ToEstablishmentResponse(establishmentLocationEntity.Establishments), Cities = ToCityResponse(establishmentLocationEntity.Cities), TypeEstablishment = ToTypeEstablishmentResponse(establishmentLocationEntity.TypeEstablishment), Foods = establishmentLocationEntity.Foods?.Select(f => new FoodResponse { Id = f.Id, FoodName = f.FoodName, PicturePathFood = f.PicturePathFood, Qualification = f.Qualification, Remarks = f.Remarks, User = ToUserResponse(f.User), TypeFoods = ToTypeFoodResponse(f.TypeFoods) }).ToList() }); }
public async Task <IActionResult> PostEstablishmentLocation([FromBody] EstablishmentLocationRequest request) { if (!ModelState.IsValid) { return(BadRequest(new Response { IsSuccess = false, Message = "Bad request", Result = ModelState })); } EstablishmentEntity establishment = await _context.Establishments.FirstOrDefaultAsync(e => e.Id == request.IdEstablishment); CityEntity city = await _context.Cities.FirstOrDefaultAsync(c => c.Id == request.IdCity); TypeEstablishmentEntity typeEstablishment = await _context.TypeEstablishments.FirstOrDefaultAsync(te => te.Id == request.IdTypeEstablishment); List <EstablishmentLocationEntity> establishmentLocationEntity = await _context.EstablishmentLocations .Include(m => m.Establishments) .Include(m => m.Foods) .ThenInclude(m => m.TypeFoods) .Include(m => m.Foods) .ThenInclude(m => m.User) .Include(m => m.Cities) .Include(m => m.TypeEstablishment) .Where(e => e.Establishments.Id == request.IdEstablishment) .ToListAsync(); var LatitudeValidation = establishmentLocationEntity.FirstOrDefault(el => el.SourceLatitude == request.SourceLatitude); var LongitudeValidation = establishmentLocationEntity.FirstOrDefault(el => el.SourceLongitude == request.SourceLongitude); if (LatitudeValidation != null & LongitudeValidation != null) { return(BadRequest(new Response { IsSuccess = false, Message = "Establishment location exist" })); } EstablishmentLocationEntity establishmentLocation = new EstablishmentLocationEntity { SourceLatitude = request.SourceLatitude, SourceLongitude = request.SourceLongitude, TargetLatitude = request.TargetLatitude, TargetLongitude = request.TargetLongitude, Remarks = request.Remarks, Establishments = establishment, Cities = city, TypeEstablishment = typeEstablishment }; _context.EstablishmentLocations.Add(establishmentLocation); await _context.SaveChangesAsync(); return(Ok(_converterHelper.ToEstablishmentLocationResponse(establishmentLocation))); }
public async Task <IActionResult> FoodsDetails(int?id) { if (id == null) { return(NotFound()); } EstablishmentLocationEntity establishmentLocationEntity = await _context.EstablishmentLocations .Include(m => m.Cities) .Include(m => m.Foods) .ThenInclude(m => m.TypeFoods) .FirstOrDefaultAsync(m => m.Id == id); if (establishmentLocationEntity == null) { return(NotFound()); } return(View(establishmentLocationEntity)); }
public async Task <IActionResult> PostFood([FromBody] FoodRequest request) { if (!ModelState.IsValid) { return(BadRequest(new Response { IsSuccess = false, Message = "Bad request", Result = ModelState })); } EstablishmentLocationEntity establishmentLocationEntity = await _context .EstablishmentLocations .FirstOrDefaultAsync(el => el.Id == request.EstablishmentLocationId); FoodEntity foodEntity = await _context.Foods.FirstOrDefaultAsync(f => f.FoodName == request.FoodName); TypeFoodEntity typeFoodEntity = await _context.TypeFoods.FirstOrDefaultAsync(f => f.Id == request.TypeFoodsId); UserEntity userEntity = await _userHelper.GetUserAsync(request.UserId); if (userEntity == null) { return(BadRequest("User doesn't exists.")); } if (foodEntity != null) { if (establishmentLocationEntity.Id == foodEntity.EstablishmentLocations.Id) { return(BadRequest(new Response { IsSuccess = false, Message = "This food exist in this place" })); } } string picturePath = string.Empty; if (request.PictureFoodArray != null && request.PictureFoodArray.Length > 0) { picturePath = await _blobHelper.UploadBlobAsync(request.PictureFoodArray, "foods"); } FoodEntity food = new FoodEntity { FoodName = request.FoodName, PicturePathFood = picturePath, Qualification = request.Qualification, Remarks = request.Remarks, TypeFoods = typeFoodEntity, EstablishmentLocationId = establishmentLocationEntity.Id.ToString(), EstablishmentLocations = establishmentLocationEntity, User = userEntity }; _context.Foods.Add(food); await _context.SaveChangesAsync(); return(Ok(_converterHelper.ToFoodResponse(food))); }