예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }