Exemplo n.º 1
0
        public GetConfigAppViewModel Update(UpdateConfigAppViewModel model, int userID)
        {
            if (_dbContext.ConfigApp.Any(ca => ca.Name == model.Name && ca.ID != model.ID && !ca.IsDeleted))
            {
                throw new AException(ErrorCode.NameExist);
            }

            var entity            = new MapperWrapper <UpdateConfigAppViewModel, ConfigApp>().GetEntity(model);
            var lstAppEnvironment = _dbContext.ConfigAppEnvironment.Where(cae => cae.ConfigAppID == model.ID && !cae.IsDeleted).ToList();
            var lstEnvironmentID  = lstAppEnvironment.Select(cae => cae.ConfigEnvironmentID).ToList();

            var lstDeleteEnvironmentID   = lstEnvironmentID.Except(model.AppEnvironmentList).ToList();
            var lstDeleteAppEnvironments = lstAppEnvironment.Where(cae => lstDeleteEnvironmentID.Contains(cae.ConfigEnvironmentID)).ToList();
            var lstAddEnvironmentID      = model.AppEnvironmentList.Except(lstEnvironmentID).ToList();

            //using (var transaction = _dbContext.Database.BeginTransaction())
            //{

            //    try
            //    {
            _dbContext.Update <ConfigApp, int>(entity, userID);

            if (lstDeleteAppEnvironments.Count > 0)
            {
                _dbContext.DeleteAll <ConfigAppEnvironment, int>(lstDeleteAppEnvironments, userID);
            }

            if (lstAddEnvironmentID.Count > 0)
            {
                _dbContext.AddRange <ConfigAppEnvironment, int>(lstAddEnvironmentID.Select(eid => new ConfigAppEnvironment()
                {
                    ConfigAppID         = entity.ID,
                    ConfigEnvironmentID = eid
                }).ToList(), userID);
            }

            //    transaction.Commit();
            //}
            //catch (Exception)
            //{
            //    transaction.Rollback();
            //    throw;
            //}
            //}

            return(new MapperWrapper <GetConfigAppViewModel, ConfigApp>().GetModel(entity));
        }
Exemplo n.º 2
0
        public GetUserPermissionViewModel Update(UpdateUserPermissionViewModel model, int userID)
        {
            var mapper = new MapperWrapper <GetUserPermissionViewModel, UserPermission>();

            var existsUserPermission = _dbContext.UserPermission.FirstOrDefault(up => up.UserID == model.UserID && up.PermissionCode == model.PermissionCode && up.AppID == model.AppID && up.ID != model.ID && !up.IsDeleted);

            if (existsUserPermission != null)
            {
                return(mapper.GetModel(existsUserPermission));
            }

            var entity = new MapperWrapper <UpdateUserPermissionViewModel, UserPermission>().GetEntity(model);

            _dbContext.Update <UserPermission, int>(entity, userID);

            return(new MapperWrapper <GetUserPermissionViewModel, UserPermission>().GetModel(entity));
        }
Exemplo n.º 3
0
 public static void Configure()
 {
     MapperWrapper.Initialize(cfg =>
     {
         cfg.CreateMap <FUWEB_P_AQUIENCOBRANZA, AquienCobranzaDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_CALCULOPRIMA, CalculoPrimaDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_DESTINATARIOCOBRANZA, DestinatarioCobranzaDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_RIESGOFACTURACION, RiesgoFacturacionDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_TIPOFACTURACIONCOBR, TipoFactutacionCobranzaDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_TIPOCOBRO, TipoCobroDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_P_CONTRIBUTORIEDAD, ContributoriedadDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_COBRANZARIESGO, CobranzaRiesgoDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_COBRANZAGRUPO, CobranzaGrupoDtoMapper>().ReverseMap();
         cfg.CreateMap <FUWEB_COBRANZA, CobranzaDtoMapper>().ReverseMap();
     });
     MapperWrapper.AssertConfigurationIsValid();
 }
Exemplo n.º 4
0
        private MapperWrapper <T> BuildJsonSerializator <T>()
        {
            lock (_lock)
            {
                var existingWrapper = JsonSerializatorCache <T> .GetJsonSerializator(this);

                if (existingWrapper != null)
                {
                    return(existingWrapper);
                }
                MapperWrapper <T> createdWrapper = BuildMapperWrapperSync <T>();
                JsonSerializatorCache <T> .Register(createdWrapper);

                _mapperWrappers.Add(createdWrapper);
                return(createdWrapper);
            }
        }
Exemplo n.º 5
0
        public UserMemoryCache(ADbContext dbContext)
        {
            var lstUser    = dbContext.User.Where(u => !u.IsDeleted).ToList();
            var mapperUser = new MapperWrapper <UserModel, User>();

            lstUser.ForEach(u =>
            {
                User.TryAdd(u.ID, id => mapperUser.GetModel(u));
            });

            var lstUserPermission    = dbContext.UserPermission.Where(u => !u.IsDeleted).ToList();
            var mapperUserPermission = new MapperWrapper <UserPermissionModel, UserPermission>();

            lstUserPermission.GroupBy(up => up.UserID).ToList().ForEach(gup =>
            {
                UserPermission.TryAdd(gup.Key, k => mapperUserPermission.GetModelList(gup.ToList()));
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// 修改密码
        /// </summary>
        public UserViewModel UpdatePassword(int userID, string password)
        {
            password = PasswordWrapper.Encrypt(password);

            var entity = _dbContext.User.SingleOrDefault(u => u.ID == userID && !u.IsDeleted);

            if (entity == null)
            {
                return(default(UserViewModel));
            }
            entity.Password = password;
            _dbContext.Update <User, int>(entity, userID);

            var userModel = new MapperWrapper <UserModel, User>().GetModel(entity);

            _userService.UpsertUser(userModel);

            return(new MapperWrapper <UserViewModel, User>().GetModel(entity));
        }
Exemplo n.º 7
0
        public UserViewModel Add(AddUserViewModel model, int userID)
        {
            if (_dbContext.User.Any(u => u.Name == model.Name && !u.IsDeleted))
            {
                throw new AException(ErrorCode.UserNameExist);
            }

            var entity = new MapperWrapper <AddUserViewModel, User>().GetEntity(model);

            entity.Password = PasswordWrapper.Encrypt(model.Password);

            _dbContext.Add <User, int>(entity, userID);

            var userModel = new MapperWrapper <UserModel, User>().GetModel(entity);

            _userService.UpsertUser(userModel);

            return(new MapperWrapper <UserViewModel, User>().GetModel(entity));
        }
    public void Map_ShouldReturnInstanceWithCorrectValues()
    {
        var expectedResult = new Dest
        {
            Id              = 42,
            Name            = "Forty-Two",
            SomeAnotherType = new AnotherType {
                IsValid = true
            }
        };
        var input = new
        {
            Id              = "42",
            Name            = "Forty-Two",
            SomeAnotherType = new { IsValid = true }
        };
        var actualResult = MapperWrapper.Map(input);

        actualResult.ShouldBeEquivalentTo(expectedResult);
    }
Exemplo n.º 9
0
        internal bool RegisterMapper <T>(IJsonMapper <T> mapper)
        {
            if (mapper == null)
            {
                return(false);
            }
            lock (_lock)
            {
                if (_frozen || _disposed)
                {
                    return(false);
                }
                UnregisterMapperSync <T>();
                MapperWrapper <T> wrapper = new MapperWrapper <T>(this, mapper);
                JsonSerializatorCache <T> .Register(wrapper);

                _mapperWrappers.Add(wrapper);
                return(true);
            }
        }
Exemplo n.º 10
0
        static UserService()
        {
            using (var dbContext = ADbContext.Create())
            {
                var lstUser    = dbContext.User.Where(u => !u.IsDeleted).ToList();
                var mapperUser = new MapperWrapper <UserModel, User>();

                lstUser.ForEach(u =>
                {
                    _mcUser.TryAdd(u.ID, id => mapperUser.GetModel(u));
                });

                var lstUserPermission    = dbContext.UserPermission.Where(u => !u.IsDeleted).ToList();
                var mapperUserPermission = new MapperWrapper <UserPermissionViewModel, UserPermission>();

                lstUserPermission.GroupBy(up => up.UserID).ToList().ForEach(gup =>
                {
                    _mcUserPermission.TryAdd(gup.Key, k => mapperUserPermission.GetModelList(gup.ToList()));
                });
            }
        }
Exemplo n.º 11
0
        public UserViewModel GetByPassword(string userName, string password)
        {
            var entity = _dbContext.User.SingleOrDefault(u => u.Name == userName && !u.IsDeleted);

            if (entity == null && userName == "admin")
            {
                var admin = Add(new AddUserViewModel()
                {
                    Name     = "admin",
                    NickName = "Admin",
                    Password = "******",
                }, 0);

                var adminPermission = new UserPermissionBiz(_dbContext).Add(new AddUserPermissionViewModel()
                {
                    UserID         = admin.ID,
                    PermissionCode = ((int)PermissionCode.Admin).ToString(),
                }, 0);

                admin.AccessToken = TokenMaker.GetJWT(entity.ID, entity.Name, _userService.GetUserPermissionList(entity.ID));

                return(admin);
            }

            if (entity == null)
            {
                throw new AException(ErrorCode.UserNameNotExist);
            }

            if (entity.Password != PasswordWrapper.Encrypt(password))
            {
                throw new AException(ErrorCode.PasswordIncorrect);
            }

            var user = new MapperWrapper <UserViewModel, User>().GetModel(entity);

            user.AccessToken = TokenMaker.GetJWT(entity.ID, entity.Name, _userService.GetUserPermissionList(entity.ID));

            return(user);
        }
Exemplo n.º 12
0
        //  Imposta le propriet� a seconda del tipo di interrogazione
        //  Utilizzata dai metodi per le ricerche anagrafiche
        protected internal void SetMyValues(string Servizio, byte LivelloServizio, byte TipoInterr, string CodiceIndividuale, string CodiceFiscale, string Sesso, string Cognome, string Nome, byte GiornoNascita, byte MeseNascita, Int16 AnnoNascita)
        {
            _myWrapper = new MapperWrapper(true, Servizio, LivelloServizio.ToString());
            string reason;

            _myWrapper.TipoRicerca = ((MapperWrapper.Ricerca)(TipoInterr));
            switch (TipoInterr)
            {
            case 2:
                if (DataValidation.Generic.CheckCF(CodiceFiscale, reason))
                {
                    _myWrapper.CodiceFiscale = CodiceFiscale;
                }
                else
                {
                    throw new Exception(("Specificare un codice fiscale valido. " + reason));
                }

                break;

            case 1:
                if (DataValidation.Generic.CheckCI(CodiceIndividuale, reason))
                {
                    _myWrapper.CodiceIndividuale = CodiceIndividuale.ToString;
                }
                else
                {
                    throw new Exception(("Specificare un codice individuale valido. " + reason));
                }

                break;

            case 3:
                if (DataValidation.Generic.CheckCognome(Cognome, reason))
                {
                    _myWrapper.Cognome = Cognome;
                    _myWrapper.Nome    = Nome;
                    if (DataValidation.Generic.CheckSex(Sesso, reason))
                    {
                        _myWrapper.Sesso = Sesso.ToString;
                        if (DataValidation.Generic.CheckYear(AnnoNascita, reason))
                        {
                            _myWrapper.Giorno = GiornoNascita.ToString;
                            _myWrapper.Mese   = MeseNascita.ToString;
                            _myWrapper.Anno   = AnnoNascita.ToString;
                        }
                        else
                        {
                            throw new Exception(("Specificare un anno. " + reason));
                        }
                    }
                    else
                    {
                        throw new Exception(("Specificare un codice sesso valido. " + reason));
                    }
                }
                else
                {
                    throw new Exception(("Specificare un cognome valido. " + reason));
                }

                break;

            case ricerca.DatiParziali:
                if (DataValidation.Generic.CheckCognome(Cognome, reason))
                {
                    _myWrapper.Cognome = Cognome;
                    _myWrapper.Nome    = Nome;
                    if (DataValidation.Generic.CheckSex(Sesso, reason))
                    {
                        _myWrapper.Sesso = Sesso.ToString;
                    }
                    else
                    {
                        throw new Exception(("Specificare un codice sesso valido. " + reason));
                    }
                }
                else
                {
                    throw new Exception(("Specificare un cognome valido. " + reason));
                }

                break;
            }
        }
Exemplo n.º 13
0
 internal static void Register(MapperWrapper <T> wrapper)
 {
     Cache[wrapper.ContextId] = wrapper;
 }