Beispiel #1
0
 public void DeleteEntireGallery()
 {
     using (_context.Database.BeginTransaction())
     {
         foreach (var img in _context.Images)
         {
             _context.Entry(img).State = EntityState.Deleted;
         }
         _context.SaveChanges();
         _context.Database.CommitTransaction();
     }
 }
Beispiel #2
0
        public async Task <int> Create(Event newEvent)
        {
            int save;

            using (_context.Database.BeginTransaction())
            {
                await _context.Events.AddAsync(newEvent);

                save = _context.SaveChanges();
                _context.Database.CommitTransaction();
            }
            return(save);
        }
Beispiel #3
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("UserName \"" + user.UserName + "\" is already taken");
            }

            CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }