Esempio n. 1
0
 public IActionResult PutClient(int id, [FromBody] ClientEntityModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             model.Id = id;
             var newClient = _mapper.Map <ClientEntityModel, Client>(model);
             _repo.ModifyClient(newClient);
             if (_repo.SaveAll())
             {
                 return(Accepted($"/api/clients/{newClient.Id}", _mapper.Map <Client, ClientEntityModel>(newClient)));
             }
         }
         else
         {
             _logger.LogError($"Failed to put client with id {id} by model validation: {ModelState}");
             return(BadRequest(ModelState));
         }
     }
     catch (Exception e)
     {
         _logger.LogError($"Failed to put client with id {id}: {e}");
     }
     return(BadRequest("Failed to edit client"));
 }
Esempio n. 2
0
 public IActionResult PostClient([FromBody] ClientEntityModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var newClient = _mapper.Map <ClientEntityModel, Client>(model);
             _repo.AddClient(newClient);
             if (_repo.SaveAll())
             {
                 return(Created($"/api/orders/{newClient.Id}", _mapper.Map <Client, ClientEntityModel>(newClient)));
             }
         }
         else
         {
             _logger.LogError($"Failed to post client with wrong model: {ModelState}");
             return(BadRequest(ModelState));
         }
     }
     catch (Exception e)
     {
         _logger.LogError($"Failed to post client: {e}");
     }
     return(BadRequest(("Failed to save new client")));
 }
        public async Task GetAll_WithOnePosts_ReturnNonEmptyResponse()
        {
            //Arrange
            var request = new ClientEntityModel()
            {
                Address   = "Street",
                City      = "City",
                FirstName = "Test",
                Id        = 0,
                LastName  = "Test",
                ZipCode   = "53-300"
            };
            var addedClient = await CreateClientAsync(request);

            //Act
            var response = await TestClient.GetAsync(ApiRoutes.Clients.GetAll);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            List <Client> clients;

            //List<Client> clientsOnServer = Serializer.Deserialize<Client>(await response.Content.ReadAsStreamAsync())
            using (var sr = new StringReader(await response.Content.ReadAsStringAsync()))
            {
                var clientsOnServer = JsonConvert.DeserializeObject <List <Client> >(sr.ReadToEnd());
                clients = clientsOnServer;
            }

            Assert.True(clients.Exists(c => c.LastName == "Test"));

            var deleteAfterTest = await TestClient.DeleteAsync(ApiRoutes.Clients.Delete + addedClient.Id);

            deleteAfterTest.StatusCode.Should().Be(HttpStatusCode.Accepted, "There is Client on DB");
        }
Esempio n. 4
0
        public void AddOrUpdateClient(ClientEntityModel cliententitymodel)
        {
            if (cliententitymodel.ClientID > 0)
            {
                // update
                var clientdata = _unitOfWork.Repository <Client>().Table().FirstOrDefault(c => c.ClientID == cliententitymodel.ClientID);

                if (clientdata == null)
                {
                    throw new Exception("Client not found");
                }
                clientdata.ClientName             = cliententitymodel.ClientName;
                clientdata.ClientName2            = cliententitymodel.ClientName2;
                clientdata.ClientCivilId          = cliententitymodel.ClientCivilId;
                clientdata.ClientCompany          = cliententitymodel.ClientCompany;
                clientdata.ClientNotes            = cliententitymodel.ClientNotes;
                clientdata.ClientAvtar            = cliententitymodel.ClientAvtar;
                clientdata.ClientEmailId          = cliententitymodel.ClientEmailId;
                clientdata.ClientMobileNo         = cliententitymodel.ClientMobileNo;
                clientdata.ClientOfficeNo         = cliententitymodel.ClientOfficeNo;
                clientdata.ClientFaxNo            = cliententitymodel.ClientFaxNo;
                clientdata.ClientAddress          = cliententitymodel.ClientAddress;
                clientdata.ClientWebsite          = cliententitymodel.ClientWebsite;
                clientdata.ClientStatus           = cliententitymodel.ClientStatus;
                clientdata.ClientDelete           = cliententitymodel.ClientDelete;
                clientdata.ClientLastModifiedDate = DateTime.Now;
                clientdata.ClientLastModifiedBy   = 1;

                _unitOfWork.Repository <Client>().Update(clientdata);
                _unitOfWork.Save();
            }
            else
            {
                //insert
                Mapper.CreateMap <ClientEntityModel, Client>();
                var ClientDetails = Mapper.Map <ClientEntityModel, Client>(cliententitymodel);

                ClientDetails.ClientName             = cliententitymodel.ClientName;
                ClientDetails.ClientName2            = cliententitymodel.ClientName2;
                ClientDetails.ClientCivilId          = cliententitymodel.ClientCivilId;
                ClientDetails.ClientCompany          = cliententitymodel.ClientCompany;
                ClientDetails.ClientNotes            = cliententitymodel.ClientNotes;
                ClientDetails.ClientAvtar            = cliententitymodel.ClientAvtar;
                ClientDetails.ClientEmailId          = cliententitymodel.ClientEmailId;
                ClientDetails.ClientMobileNo         = cliententitymodel.ClientMobileNo;
                ClientDetails.ClientOfficeNo         = cliententitymodel.ClientOfficeNo;
                ClientDetails.ClientFaxNo            = cliententitymodel.ClientFaxNo;
                ClientDetails.ClientAddress          = cliententitymodel.ClientAddress;
                ClientDetails.ClientWebsite          = cliententitymodel.ClientWebsite;
                ClientDetails.ClientStatus           = cliententitymodel.ClientStatus;
                ClientDetails.ClientDelete           = cliententitymodel.ClientDelete;
                ClientDetails.ClientLastModifiedDate = DateTime.Now;
                ClientDetails.ClientLastModifiedBy   = 1;
                ClientDetails.ClientCreatedBy        = 1;
                ClientDetails.ClientCreatedDate      = DateTime.Now;
                _unitOfWork.Repository <Client>().Add(ClientDetails);
                _unitOfWork.Save();
            }
        }
Esempio n. 5
0
        protected async Task <Client> CreateClientAsync(ClientEntityModel request)
        {
            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            var myContent     = JsonConvert.SerializeObject(request, serializerSettings);
            var stringContent = new StringContent(myContent, Encoding.UTF8, "application/json");
            var response      = await TestClient.PostAsync(ApiRoutes.Clients.Post, stringContent);

            return(JsonConvert.DeserializeObject <Client>(await response.Content.ReadAsStringAsync()));
        }
Esempio n. 6
0
        /// <summary>
        /// Gets all users.
        /// </summary>
        /// <returns></returns>



        public List <Client> GetAllActiveClient(ClientEntityModel model)
        {
            return(_unitOfWork.Repository <Client>().Table().Where(m => m.ClientDelete == false && m.ClientStatus == true).ToList());
        }