public void AddFullManager(SevenWondersContext db, FullManagerViewModel user, int[] countries) { if (db.Users.Any(x => x.Email == user.Email)) { throw new OverflowException("user with this email is already exist"); } Utils utils = new Utils(); string password = utils.GetEncodedHash(user.Password, Security.solt); db.Users.Add(new User() { Email = user.Email, Password = password, RoleId = 3 }); Manager manager = new Manager() { DateOfBirth = user.DateOfBirth.ToUniversalTime(), FirstName = user.FirstName, LastName = user.LastName, PhoneNumber = user.PhoneNumber, Email = user.Email, IsDeleted = false }; db.Managers.Add(manager); db.SaveChanges(); AddCountriesForManager(db, manager, countries); }
public void EditFullManager(SevenWondersContext db, FullManagerViewModel user, int[] countries) { Manager manager = db.Managers.Find(user.Id); var userFromDb = db.Users.FirstOrDefault(x => x.Email == manager.Email); manager.LastName = user.LastName; manager.FirstName = user.FirstName; manager.Email = user.Email; manager.PhoneNumber = user.PhoneNumber; manager.DateOfBirth = user.DateOfBirth; db.Entry(manager).State = EntityState.Modified; db.SaveChanges(); Utils utils = new Utils(); if (user.Password != userFromDb.Password) { userFromDb.Password = utils.GetEncodedHash(user.Password, Security.solt); } userFromDb.Email = user.Email; AddCountriesForManager(db, manager, countries); db.Entry(userFromDb).State = EntityState.Modified; db.SaveChanges(); }