public ActionResult <UserReadDto> CreateUser(UserCreateDto userCreateDto) { var userModel = _mapper.Map <User>(userCreateDto); _repository.CreateUser(userModel); _repository.SaveChanges(); var userReadDto = _mapper.Map <UserReadDto>(userModel); return(CreatedAtRoute(nameof(GetUserById), new { Id = userReadDto.Id }, userReadDto)); }
public async Task <ActionResult <AppResponse <string> > > ScrapeAndSave() { AppResponse <string> appResponse = null; try { string msg = "Products are already exist in the database."; string result = ""; if (!(await dbRepo.DataExists <Product>())) { Product[] products = await scraping.GetData(); await dbRepo.AddRange(products); await dbRepo.SaveChanges(); msg = ""; result = "ok"; } appResponse = new AppResponse <string> { Result = result, ErrorMessage = msg }; } catch (Exception e) { appResponse = new AppResponse <string> { ErrorMessage = e.Message }; } return(appResponse); }