Exemple #1
0
 private void validate(postofficeDTO postoffice)
 {
     if (string.IsNullOrEmpty(postoffice.Name))
     {
         throw new ArgumentException("Name повинне містити значення!");
     }
 }
Exemple #2
0
        public void Addpostoffice(postofficeDTO postoffice)
        {
            var user     = SecurityContext.GetUser();
            var userType = user.GetType();

            if (userType != typeof(Admin) ||
                userType != typeof(Accountant))
            {
                throw new MethodAccessException();
            }
            if (postoffice == null)
            {
                throw new ArgumentNullException(nameof(postoffice));
            }

            validate(postoffice);

            var mapper           = new MapperConfiguration(cfg => cfg.CreateMap <postofficeDTO, postoffice>()).CreateMapper();
            var postofficeEntity = mapper.Map <postofficeDTO, postoffice>(postoffice);

            _database.postoffices.Create(postofficeEntity);
        }