public async Task <CreateCategoryResponseModel> CreateCategory(CreateCategoryRequestModel createCategoryRequestModel) { if (createCategoryRequestModel == null) { throw new ArgumentNullException(nameof(createCategoryRequestModel)); } var createCategoryResponseModel = new CreateCategoryResponseModel(); try { await _inMemoryStorage.Save( new Category { Id = createCategoryRequestModel.Id, Description = createCategoryRequestModel.Description, Name = createCategoryRequestModel.Name, UserId = createCategoryRequestModel.UserId, }, true) .ConfigureAwait(false); } catch (Exception ex) { createCategoryResponseModel.ErrorMessage = ex.Message; } return(createCategoryResponseModel); }
public async Task <CreateProductResponseModel> CreateProduct(CreateProductRequestModel productRequestModel) { if (productRequestModel == null) { throw new ArgumentNullException(nameof(productRequestModel)); } var createProductResponseModel = new CreateProductResponseModel(); try { await _inMemoryStorage.Save( new Product { Id = productRequestModel.Id, CreateDate = DateTime.Now, Name = productRequestModel.Name, CategoryId = productRequestModel.CategoryId, Description = productRequestModel.Description, UserId = productRequestModel.UserId, }, true) .ConfigureAwait(false); } catch (Exception ex) { createProductResponseModel.ErrorMessage = ex.Message; } return(createProductResponseModel); }
public Ticket TakeTicket(Ticket ticket) { if (_inMemoryStorage.Tickets.LastOrDefault() != null) { // ReSharper disable once PossibleNullReferenceException ticket.Number = ++_inMemoryStorage.Tickets.LastOrDefault().Number; } else { ticket.Number = 1; } var ticketEntity = _mapper.Map <TicketEntity>(ticket); _inMemoryStorage.Tickets.Add(ticketEntity); _inMemoryStorage.Save(); return(ticket); }