public async Task <StoresResponseModel> UpdateStore(StoresInformation storesInformation, StoresInformation originalInformation) { // update store using context and returning info with linq try { var updateInfo = StoresInformation.MapUpdate(storesInformation, originalInformation); StoresResponseModel response = new StoresResponseModel(); _context.Entry(updateInfo).State = EntityState.Modified; await _context.SaveChangesAsync(); var list = await(from d in _context.Stores select new StoresInformation() { Id = d.Id, Address = d.Address, Name = d.Name }).ToListAsync(); response = StoresResponseModel.Map(list); return(response); } catch (Exception e) { throw e; } }
public async Task <IActionResult> AddStore(StoresInformation storesInformation) { try { var response = await _storeServices.AddStore(storesInformation); return(Ok(response)); } catch (Exception e) { return(BadRequest(ErrorResponse.Map(e))); } }
public async Task <StoresResponseModel> AddStore(StoresInformation storesInformation) { //add store using context and returning info with lambdas and context. try { _context.Stores.Add(storesInformation); await _context.SaveChangesAsync(); List <StoresInformation> response = await _context.Stores.Where(x => x.Id == storesInformation.Id).ToListAsync(); StoresResponseModel storesResponseModel = StoresResponseModel.Map(response); return(storesResponseModel); } catch (Exception e) { throw e; } }
public async Task <IActionResult> UpdateStore(int id, StoresInformation storesInformation) { // find store if note return error var findStore = _context.Stores.Find(id); if (findStore == null) { return(NotFound()); } //detach for later use _context.Entry(findStore).State = EntityState.Detached; try { var response = await _storeServices.UpdateStore(storesInformation, findStore); return(new OkObjectResult(response)); } catch (Exception e) { return(BadRequest(ErrorResponse.Map(e))); } }
public async Task <StoresResponseModel> AddStore(StoresInformation storesInformation) { return(await _storesDataSet.AddStore(storesInformation)); }
public async Task <StoresResponseModel> UpdateStore(StoresInformation storesInformation, StoresInformation originalInformation) { return(await _storesDataSet.UpdateStore(storesInformation, originalInformation)); }