public async Task <bool> CreateAsync(FiverrServices model) { await _dataContext.FiverrServices.AddAsync(model); var created = await _dataContext.SaveChangesAsync(); return(created > 0); }
public async Task <bool> UpdateAsync(FiverrServices model, string UserId) { var fiverrService = await _dataContext.FiverrServices.SingleOrDefaultAsync(x => x.Id == model.Id && x.UserId == UserId); if (fiverrService == null) { return(false); } _dataContext.FiverrServices.Update(model); var updated = await _dataContext.SaveChangesAsync(); return(updated > 0); }
public async Task <IActionResult> Create(CreateFiverrServiceRequest request) { try { var newId = Guid.NewGuid(); var model = new FiverrServices { Id = newId, Title = request.title, FiverrURL = request.fiverrURL, Description = request.description, Image = UploadedFile(request.image), Rate = request.rate, Categories = request.categories, UserId = HttpContext.GetUserId(), }; await _service.CreateAsync(model); var locationUri = _uriService.GetFiverrServiceUri(model.Id.ToString()); var response = new CreateFiverrServiceResponse { Title = model.Title, FiverrURL = model.FiverrURL, Description = model.Description, Rate = model.Rate, Image = model.Image, Categories = model.Categories, UserId = model.UserId, }; return(Created(locationUri, response)); } catch (Exception ex) { return(StatusCode(500, $"Internal Server error: {ex}")); } }