예제 #1
0
        public void Test_FindClientById()
        {
            var dac = new ClientDAC();

            var result = dac.FindById <Client>(1);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, new Client().GetType());
        }
        /// <summary>
        /// Add method.
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public Client Save(Client dto)
        {
            Client update;

            if (dto.Id > 0)
            {
                update = clientDAC.FindById <Client>(dto.Id);
            }
            else
            {
                update = new Client {
                    CreatedOn = DateTime.Now
                };
            }

            if (string.IsNullOrEmpty(dto.FirstName))
            {
                throw new BusinessException("b.validation.client.firstname.invalid");
            }
            else
            {
                update.FirstName = dto.FirstName;
            }

            update.LastName = string.IsNullOrEmpty(dto.LastName)
                ? throw new BusinessException("b.validation.client.lastname.invalid")
                : dto.LastName;

            update.City = string.IsNullOrEmpty(dto.City)
                ? throw new BusinessException("b.validation.client.city.invalid")
                : dto.City;

            if (dto.CountryId > 0)
            {
                var country = countryBusiness.Find(dto.Id);

                if (country != null)
                {
                    update.CountryId = dto.CountryId;
                }
                else
                {
                    throw new BusinessException("b.validation.client.country.invalid");
                }
            }
            else
            {
                throw new BusinessException("b.validation.client.country.invalid");
            }


            if (update.Rowid == Guid.Empty)
            {
                update.Rowid = Guid.NewGuid();
            }

            update.ChangedOn = DateTime.Now;
            var saved = clientDAC.Save(dto);

            return(saved);
        }