Example #1
0
        public EditReturnModel InsertAdministrator(string password, string email, string firstname, string lastname, bool gender,
                                          DateTime? birthday, string address, string district, string province,
                                          string phone, string facebookId, bool isLocked, int typeAccount)
        {
            try
            {
                var userId = Guid.NewGuid();

                //Check facebook Id
                var facebook = !string.IsNullOrEmpty(facebookId) &&
                               DataContext.Members.Any(m => m.FacebookId == facebookId);

                if (facebook)
                    return new EditReturnModel { Message = "FAE", Result = false };

                var admin = new Administrator()
                {
                    UserId = userId,
                    Birthday = birthday,
                    Password = Cryptography.CreateShaHash(new[] { password, userId.ToString() }),
                    Gender = gender,
                    Email = email,
                    FirstName = firstname,
                    LastName = lastname,
                    Phone = phone,
                    FacebookId = facebookId,
                    IsLoked = isLocked,
                    RegisterDate = DateTime.UtcNow.AddHours(7),
                    TypeAccount = typeAccount,
                    Address = address,
                    District = district,
                    Province = province
                };

                DataContext.Administrators.Add(admin);
                var result = DataContext.SaveChanges();
                return new EditReturnModel { Result = result > 0 };
            }
            catch (Exception exception)
            {
                return new EditReturnModel { Result = false, Message = exception.ToString() };
            }
        }
        /// <summary>
        /// Create a new administrator account
        /// </summary>
        /// <param name="username">The username for the new account</param>
        /// <param name="password">The password for the new account</param>
        /// <param name="email">The email for the new account</param>
        /// <returns>The newly created administrator account</returns>
        public Administrator CreateAdministrator(string username, string password, string email)
        {
            using (MediathekEntities context = new MediathekEntities())
            {
                var admin = new Administrator();

                admin.Username = username;
                admin.Password = password;
                admin.Email = email;

                context.AddToAdministrators(admin);
                context.SaveChanges();

                return admin;
            }
        }