示例#1
0
        public AdministratorInfo ApiInsert(AdministratorInfoCreateUpdate adminInfoToInsert, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                var dbAdminInfo = new AdministratorInfoDatabase();

                adminInfoToInsert.Load(dbAdminInfo);

                if (!InsertValidate(dbAdminInfo.UserName, dbAdminInfo.Password, dbAdminInfo.Email, dbAdminInfo.Mobile, out errorMessage))
                {
                    return(null);
                }

                dbAdminInfo.Password         = EncodePassword(dbAdminInfo.Password, EPasswordFormatUtils.GetEnumType(dbAdminInfo.PasswordFormat), out var passwordSalt);
                dbAdminInfo.PasswordSalt     = passwordSalt;
                dbAdminInfo.CreationDate     = DateTime.Now;
                dbAdminInfo.LastActivityDate = DateTime.Now;

                using (var connection = GetConnection())
                {
                    var identity = connection.Insert(dbAdminInfo);
                    if (identity > 0)
                    {
                        dbAdminInfo.Id = Convert.ToInt32(identity);
                    }
                }

                return(dbAdminInfo.ToAdministratorInfo());
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(null);
            }
        }
示例#2
0
        public AdministratorInfo ApiUpdate(int id, AdministratorInfoCreateUpdate adminInfoToUpdate, out string errorMessage)
        {
            var adminInfo = ApiGetAdministrator(id);

            if (!UpdateValidate(adminInfoToUpdate, adminInfo.UserName, adminInfo.Email, adminInfo.Mobile, out errorMessage))
            {
                return(null);
            }

            var dbUserInfo = new AdministratorInfoDatabase(adminInfo);

            adminInfoToUpdate.Load(dbUserInfo);

            dbUserInfo.Password       = adminInfo.Password;
            dbUserInfo.PasswordFormat = adminInfo.PasswordFormat;
            dbUserInfo.PasswordSalt   = adminInfo.PasswordSalt;

            using (var connection = GetConnection())
            {
                connection.Update(dbUserInfo);
            }

            return(dbUserInfo.ToAdministratorInfo());
        }