Ejemplo n.º 1
0
        public UserOfService CreateUser(UserOfService model)
        {
            var entryEntity = _context.UsersOfService.Add(model);

            _context.SaveChanges();
            return(entryEntity.Entity);
        }
Ejemplo n.º 2
0
        public bool DeleteUser(UserOfService model)
        {
            var entity = _context.UsersOfService.FirstOrDefault(us => us.Id == model.Id);

            if (entity != null)
            {
                _context.UsersOfService.Remove(entity);
                _context.SaveChanges();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static void Initialize(Context context)
        {
            context.Database.EnsureCreated();
            //if (context.DayEvents.Any())
            //{
            //    return;
            //}

            var roles = new Role[]
            {
                new Role()
                {
                    Name = "Employee"
                },
                new Role()
                {
                    Name = "Manager"
                }
            };

            foreach (var role in roles)
            {
                context.Roles.Add(role);
            }
            context.SaveChanges();

            var users = new UserOfService[]
            {
                new UserOfService()
                {
                    CryptedPassword = PasswordCrypt.CreateDbPassword("qwerty123"), Email = "*****@*****.**", Username = "******", Role = roles[0]
                },
                new UserOfService()
                {
                    CryptedPassword = PasswordCrypt.CreateDbPassword("qwerty123"), Email = "*****@*****.**", Username = "******", Role = roles[0]
                },
                new UserOfService()
                {
                    CryptedPassword = PasswordCrypt.CreateDbPassword("qwerty123"), Email = "*****@*****.**", Username = "******", Role = roles[0]
                },
                new UserOfService()
                {
                    CryptedPassword = PasswordCrypt.CreateDbPassword("manager"), Email = "*****@*****.**", Username = "******", Role = roles[1]
                }
            };

            foreach (var user in users)
            {
                context.UsersOfService.Add(user);
            }
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public bool UpdateUser(UserOfService model)
        {
            var updatingEntity = _context.UsersOfService.FirstOrDefault(u => u.Id == model.Id);

            if (updatingEntity != null)
            {
                updatingEntity.Update(model);
                _context.Entry(updatingEntity).State = EntityState.Modified;
                _context.SaveChanges();
                return(true);
            }
            return(false);
        }