public void ComplexTypePopulateSimpleTestPopulateDeep()
        {

            var Source = new Client
            {
                Name = "Rafael",
                Age = 22,
                NotSimple = new Client { Name = "Jose", Age = 17 },
                Address = new Address
                {
                    City = "Obregon",
                    Street = "E Baca Calderon"
                }
            };

            var Dest = new ClientDTO { Address = new Address() } ;

            var lastDestAddress = Dest.Address;
            LinqEx.PopulateObjectSimple(Source, Dest);

            Assert.AreEqual(Dest.Name, Source.Name);
            Assert.AreEqual(Dest.Age, Source.Age);
            Assert.IsNull(Dest.NotSimple);

            Assert.IsNotNull(Dest.Address);

            //Deep cloning should result in different instances
            Assert.AreNotEqual(Source.Address, Dest.Address);
            //Deep cloning should populate (not instantiate) Dest.Address
            Assert.AreEqual(lastDestAddress, Dest.Address);

            Assert.AreEqual(Source.Address.City, Dest.Address.City);
            Assert.AreEqual(Source.Address.Street, Dest.Address.Street);
        }
        public void PopulateObject()
        {
            var A = new Client { Age = 21, Name = "Rafael", InternalData = "Hello", NotSimple = null };
            var B = new ClientDTO();

            LinqEx.PopulateObject(A, B);

        }
        public void PopulateObjectTest()
        {
            var Source = new Client { Name = "Rafael", Age = 22 };
            var Dest = new ClientDTO();

            LinqEx.PopulateObject(Source, Dest, x => true);

            Assert.AreEqual(false, Dest.LegalDrinking);
        }
Beispiel #4
0
        public ClientDTO MapperToDTO(Client Client)
        {
            ClientDTO clientDTO = new ClientDTO
            {
                Id       = Client.Id,
                Name     = Client.Name,
                LastName = Client.LastName,
                Email    = Client.Email
            };

            return(clientDTO);
        }
Beispiel #5
0
        public Client MapperToEntity(ClientDTO clientDTO)
        {
            Client client = new Client
            {
                Id       = clientDTO.Id,
                Name     = clientDTO.Name,
                LastName = clientDTO.LastName,
                Email    = clientDTO.Email
            };

            return(client);
        }
        private Client SetClient(ClientDTO dto)
        {
            var client = _context.Clients
                         .FirstOrDefault(c => c.Name == dto.Name && c.ExploitationPlace == dto.ExploitationPlace)
                         ?? new Client
            {
                Name = dto.Name,
                ExploitationPlace = dto.ExploitationPlace
            };

            return(client);
        }
Beispiel #7
0
 public IHttpActionResult Get(int id)
 {
     try
     {
         ClientDTO client = repository.GetClient(id);
         return(Ok(client));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Beispiel #8
0
        public async Task CreateItem(ClientDTO ItemDTO)
        {
            if (ItemDTO == null)
            {
                throw new ArgumentNullException();
            }

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ClientDTO, Client>()).CreateMapper();

            Database.Clients.Create(mapper.Map <ClientDTO, Client>(ItemDTO));
            await Database.SaveAsync();
        }
Beispiel #9
0
 public ActionResult Edit(ClientDTO client)
 {
     if (ModelState.IsValid)
     {
         client.ModifiedBy = this.User.Id;
         this._IClientService.Update(new ClientDTOList {
             client
         });
     }
     this.DataBind();
     return(RedirectToAction("Edit", new { Id = client.Id }));
 }
Beispiel #10
0
        public IEnumerable <CaseDTO> GetClientCases(ClientDTO client)
        {
            Client _client = _database.Clients.Find(c => c.Id == client.Id).FirstOrDefault();

            if (_client == null)
            {
                throw new ValidationException("Клиент не найден", "");
            }
            var cases = _database.Cases.Find(c => c.Id == _client.CaseUserId);

            return(GetListCases(cases));
        }
Beispiel #11
0
        public int RegisterNewClient(ClientDTO newClient)
        {
            validateNewClientDataIsCorrect(newClient);
            validator.validateUserIsNotRegistered(newClient);

            Client clientToAdd = convertDTO(newClient);

            unitOfWork.ClientRepository.Insert(clientToAdd);
            unitOfWork.Save();

            return(clientToAdd.ClientId);
        }
        public void DeleteClient(ClientDTO clientDto)
        {
            var bookings = Database.Bookings.Find(x => x.ClientID == clientDto.ClientID);

            if (bookings != null)
            {
                Database.Bookings.DeleteRange(bookings);
            }

            Database.Clients.Delete(clientDto.ClientID);
            Database.Save();
        }
Beispiel #13
0
        public void ValidatRegisterClient_5()
        {
            IClientService service = new ClientService(new UnitOfWork());

            ClientDTO clientToAdd = new ClientDTO();

            clientToAdd.Email            = "validMailmail.com";
            clientToAdd.Password         = "******";
            clientToAdd.RepeatedPassword = "******";

            service.RegisterNewClient(clientToAdd);
        }
Beispiel #14
0
        public ClientDTO InsertClient(ClientDTO client)
        {
            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            Client newClient = Mapper.Map <Client>(client);

            UnitOfWork.Clients.Insert(newClient);
            UnitOfWork.Save();
            return(Mapper.Map <ClientDTO>(newClient));
        }
        public IHttpActionResult MakeOrder(BookDTO book, ClientDTO client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.MakeOrder(book, client);


            return(Created(new Uri(Request.RequestUri + "/" + book.Title), book.Title));
        }
Beispiel #16
0
 public IHttpActionResult Post(ClientDTO client)
 {
     _clientServ.EditClient(client);
     if (ModelState.IsValid)
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
        public void Add()
        {
            var newClient = new ClientDTO();

            newClient.CompanyName = CompanyName;
            newClient.PostalCode  = string.Format("{0}-{1}", PostalCode1, PostalCode2);
            newClient.Address     = Address;
            newClient.Email       = Email;
            newClient.PhoneNumber = PhoneNumber;
            ClientService.Add(newClient);
            TryClose();
        }
Beispiel #18
0
        public IQueryable <ClientDTO> GetAll()
        {
            IQueryable <ClientDAO> resultClientDAOQueryable = clientRepository.GetAll();
            List <ClientDTO>       resultClientDTOList      = new List <ClientDTO>();

            foreach (ClientDAO clientDAO in resultClientDAOQueryable)
            {
                ClientDTO resultClientDTO = converter.fromDAOTodTO(clientDAO);
                resultClientDTOList.Add(resultClientDTO);
            }
            return(resultClientDTOList.AsQueryable <ClientDTO>());
        }
Beispiel #19
0
        public void GetClientByLogin([Values(1, 2)] int client_id, [Values(1, 2)] int device_id, [Values("login")] string login)
        {
            var cltDTO = new ClientDTO {
                login = login, client_id = client_id, device_id = device_id
            };

            clientDal.Setup(m => m.GetByLogin(It.IsNotNull <string>())).Returns(cltDTO);

            var res = manager.GetClientByLogin(login);

            Assert.IsTrue(device_id == res.device_id);
        }
Beispiel #20
0
        public void Delete(ClientDTO client)
        {
            IWindowManager manager = new WindowManager();

            // DeleteConfirmationViewModel modify = new DeleteConfirmationViewModel();
            // bool? showDialogResult = manager.ShowDialog(modify, null, null);
            // if (showDialogResult != null && showDialogResult == true)
            // {
            ClientService.Delete(client);
            // }
            Reload();
        }
Beispiel #21
0
        public void Read(TProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            try
            {
                TField field;
                iprot.ReadStructBegin();
                while (true)
                {
                    field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.Struct)
                        {
                            Meci = new MeciDTO();
                            Meci.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.Struct)
                        {
                            LoggedInClient = new ClientDTO();
                            LoggedInClient.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    default:
                        TProtocolUtil.Skip(iprot, field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
        }
Beispiel #22
0
        public void AddClient(ClientDTO clientDto)
        {
            Client client = new Client
            {
                name  = clientDto.name,
                sname = clientDto.sname,
                email = clientDto.email
            };

            Database.Clients.Create(client);
            Database.Save();
        }
        public ClientDTO GetClient(Guid Client_Id)
        {
            ClientDTO clientDTO = new ClientDTO();

            try
            {
                Client client = oauth.Client.SingleOrDefault(x => x.Client_Id == Client_Id);
                clientDTO = mapper.Map <ClientDTO>(client);
            }
            catch { }
            return(clientDTO);
        }
 public ClientViewModel(ClientDTO dto)
 {
     Id             = dto.Id;
     CreatedAt      = dto.CreatedAt;
     FirstName      = dto.FirstName;
     LastName       = dto.LastName;
     PhoneNumber    = dto.PhoneNumber;
     Email          = dto.Email;
     DocumentNumber = dto.DocumentNumber;
     BirthDate      = dto.BirthDate;
     Address        = new AddressViewModel(dto.Address);
 }
        public async Task <Response> Insert(ClientDTO client)
        {
            Response        response = new Response();
            ClientValidator validate = new ClientValidator();

            ValidationResult result = validate.Validate(client);

            Response password = PasswordValidator.CheckPassword(client.Password, client.BirthDate);

            //Verifica se a senha está dentro dos padrões, caso esteja, hasheia e ela
            if (password.HasErrors())
            {
                response.Errors.Add(password.Errors.ToString());
            }
            else
            {
                client.Password = HashUtils.HashPassword(client.Password);
            }

            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    //Caso haja erros no validator, serão adicionados na response.Errors do client
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }

            if (response.HasErrors())
            {
                return(response);
            }
            else
            {
                try
                {
                    client.AccessLevel        = DataTransferObject.Enums.EAccessLevel.Client;
                    client.SystemEntranceDate = DateTime.Now;
                    client.IsActive           = true;

                    return(response = await _iClientRepository.Insert(client));
                }
                catch (Exception ex)
                {
                    _log.Error(ex + "\nStackTrace: " + ex.StackTrace);
                    response.Errors.Add("DataBase error, contact the system owner");
                    return(response);
                }
            }
        }
Beispiel #26
0
        public async Task <ActionResult> EditPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClientDTO client = new ClientDTO();

            using (_httpClient = new HttpClient())
            {
                HttpResponseMessage response = await _httpClient.GetAsync($"{_apiPath}{_clientAPI}/{id}");

                if (response.IsSuccessStatusCode)
                {
                    client = await response.Content.ReadAsAsync <ClientDTO>();
                }
            }
            if (TryUpdateModel(client, "",
                               new string[] { "Title", "Credits", "DepartmentID" }))
            {
                try
                {
                    var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("ID", client.ID.ToString()),
                        new KeyValuePair <string, string>("Name", client.Name),
                        new KeyValuePair <string, string>("City", client.City),
                        new KeyValuePair <string, string>("Email", client.Email),
                        new KeyValuePair <string, string>("PostalCode", client.PostalCode),
                        new KeyValuePair <string, string>("Street", client.Street),
                        new KeyValuePair <string, string>("BuildingNumber", client.BuildingNumber.ToString()),
                        new KeyValuePair <string, string>("Password", client.Password)
                    });

                    using (_httpClient = new HttpClient())
                    {
                        HttpResponseMessage response =
                            await
                            _httpClient.PostAsync(new Uri($"{_apiPath}{_clientAPI}"), content);
                    }

                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("",
                                             "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return(View(client));
        }
Beispiel #27
0
        public void GoToClient(ClientDTO selectedClient)
        {
            var data = new ClientDisplayData
            {
                Client   = selectedClient,
                Mode     = DisplayModes.Editing,
                CameFrom = ModesEnum.AddBooking
            };

            Storage.Instance.ChangeClientDisplayData(data);

            NavigationManager.Instance.Navigate(ModesEnum.Client);
        }
Beispiel #28
0
        public ClientDTO toDTO()
        {
            ClientDTO dto = new ClientDTO()
            {
                ClientID     = this.ClientID,
                FirstMidName = this.FirstMidName,
                LastName     = this.LastName,
                BirthDate    = this.BirthDate,
                Active       = this.Active
            };

            return(dto);
        }
Beispiel #29
0
        public void Create(ClientDTO client)
        {
            var mapper       = new MapperConfiguration(cfg => cfg.CreateMap <Author, AuthorDTO>()).CreateMapper();
            var clientCreate = new Client
            {
                FullName         = client.FullName,
                Phone            = client.Phone,
                Passport         = client.Passport,
                RegistrationDate = DateTime.Now,
            };

            Database.Clients.Create(clientCreate);
        }
Beispiel #30
0
        public static ClientDTO MapClient(SClient client)
        {
            ClientDTO clientDTO = new ClientDTO
            {
                Id       = client.Id,
                Name     = client.Name,
                LastName = client.LastName,
                Age      = client.Age,
                Cart     = MapCart(client.Cart)
            };

            return(clientDTO);
        }
 public IHttpActionResult CreateClient([FromBody]ClientDTO newClient)
 {
     try
     {
         clientDA = new ClientDA();
         clientDA.CreateClient(newClient);
         return Ok();
     }
     catch (System.Exception ex)
     {
         return InternalServerError(ex);
     }
 }
Beispiel #32
0
        /// <summary>
        /// GET CLIENT BY MAIL
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public ClientDTO GetClientByMail(string email)
        {
            var clientMapper = _dbContext.Clients.FirstOrDefault(x => x.Email == email);

            if (clientMapper == null)
            {
                return(null);
            }

            ClientDTO client = _mapper.Map <ClientDTO>(clientMapper);

            return(client);
        }
Beispiel #33
0
        public ClientDTO GetClient(int id)
        {
            var client    = Database.Clients.Get(id);
            var clientDTO = new ClientDTO()
            {
                FullName         = client.FullName,
                Phone            = client.Phone,
                Passport         = client.Passport,
                RegistrationDate = client.RegistrationDate,
            };

            return(clientDTO);
        }
        public ResponseContract RegisterClient(ClientDTO client)
        {
            ResponseContract response = new ResponseContract();

            try
            {
                Client newClient = client.MapTo();
                ClientBusiness clientBLL = new ClientBusiness();

                string error = clientBLL.RegisterClient(newClient);

                if (!string.IsNullOrWhiteSpace(error))
                    response.ErrorMessage = error;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
            }

            return response;
        }