public async Task SavePostAndLocation(AddPostAndLocation apal) { Location loc = new Location(); loc.Address = apal.Address; loc.Latitude = apal.Latitude; loc.Longitude = apal.Longitude; var LocationExists = _context.Location.FirstOrDefault(x => x.Address == loc.Address && x.Latitude == loc.Latitude && x.Longitude == loc.Longitude); Post post = new Post(); if (LocationExists == null) { _context.Location.Add(loc); await _context.SaveChangesAsync(); post.LocationID = loc.ID; } else { post.LocationID = LocationExists.ID; } post.Title = apal.Title; post.Description = apal.Description; post.Time = apal.Time; post.Active = apal.Active; post.PostImage = apal.PostImage; post.UserDataID = apal.UserDataID; post.CategoryID = apal.CategoryID; post.CityID = apal.CityID; _context.Posts.Add(post); await _context.SaveChangesAsync(); }
public async Task <ActionResult <Post> > PostPost(AddPostAndLocation apal) { await _IPostsUI.SavePostAndLocation(apal); return(Ok()); }
public Task SavePostAndLocation(AddPostAndLocation apal) { return(_IPostsDAL.SavePostAndLocation(apal)); }