Beispiel #1
0
        public async Task <ActionResult <ClientReadDto> > GetClientById(Guid clientId)
        {
            var clientFromRepo = await _clientsRepo.GetClientById(clientId);

            if (clientFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <ClientReadDto>(clientFromRepo)));
        }
Beispiel #2
0
        public ActionResult Details(int?id)
        {
            var userName = GetUserName();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Client client = _repository.GetClientById(id);

            if (client == null || !client.ClientOwner.Equals(userName))
            {
                return(HttpNotFound());
            }

            return(View(client));
        }
        public IActionResult PostOrder([FromBody] OrderEntityModel model)
        {
            try
            {
                var newOrder = _mapper.Map <OrderEntityModel, Order>(model);
                CheckDataValidation(newOrder);
                if (!ModelState.IsValid)
                {
                    _logger.LogDebug($"bad request from post order made by : {ModelState} ");
                    return(BadRequest(ModelState));
                }

                var client = _clientsRepo
                             .GetClientById(model.ClientId);

                if (client == null)
                {
                    ModelState.AddModelError("Errors", "Client is not in Data Base");
                    return(BadRequest(ModelState));
                }

                string firsName = client.FirstName.ToUpper();
                string lastName = client.LastName.ToUpper();

                newOrder.OrderNumber =
                    $"{firsName[0]}{lastName.Substring(0, 3)}-{DateTime.Now.Year}{DateTime.Now.Month}{DateTime.Now.Day}{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}";

                newOrder.Client = _clientsRepo
                                  .GetAllClients()
                                  .FirstOrDefault(c => c.Id == model.ClientId);
                _repo.AddOrder(newOrder);
                if (_repo.SaveAll())
                {
                    return(Created($"/api/orders/{newOrder.Id}", _mapper.Map <Order, OrderEntityModel>(newOrder)));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Failed to post order: {e}");
            }
            return(BadRequest(("Failed to save new order")));
        }
Beispiel #4
0
 public ActionResult <IEnumerable <Client> > GetClientsById(int id)
 {
     try
     {
         var client = _mapper.Map <Client, ClientEntityModel>(_repo.GetClientById(id));
         if (client != null)
         {
             return(Ok(client));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         _logger.LogError($"Failed to get client by id {id}: {e}");
         return(BadRequest(("Failed to get client")));
     }
 }
        public async Task <Client> GetClientById(string id)
        {
            var client = await _clientsRepository.GetClientById(id);

            return(MapToClientDtoOrNull(client));
        }
Beispiel #6
0
 public Client GetClientById(int id)
 {
     return(_clientsRepository.GetClientById(id));
 }