public override void Delete(Account account)
        {
            var eventStore = new EventStore()
              {
            Date = DateTime.UtcNow,
            EventName = Events.DeleteAccount,
            Payload = account
              };

              this.eventStoreRepository.Add(eventStore);
              this.AccountRepository.Delete(account);
        }
        public void Delete(Account account)
        {
            string filename = this.FilenameFromAccountName(account.ApiKey.ToString());

            if (this._accounts.Any(q => q.ApiKey == account.ApiKey))
            {
                this._accounts.Remove(account);
            }

            File.Delete(filename);
            //return account;
        }
 public void MapFrom(Account account, IEnumerable<Query> queries)
 {
     Id = account.Id;
     FullName = account.FullName;
     UserName = account.UserName;
     Email = account.Email;
     PhoneNumber = account.PhoneNumber;
       Notitie = account.Notitie;
     ApiKey = account.ApiKey;
     IsAdministrator = account.IsAdministrator;
     IsEditor = account.IsEditor;
     QueryAccess =
         queries.Select(
             q => new QueryAccessModel() {
                 Alias = q.Alias,
                 Label = q.Label,
                 View = q.ApiKeys.Any(k => k.Equals(account.ApiKey)),
                 Edit = q.Authorization.Any(a => a.Operation == AuthorizationOperations.Edit && a.AccountId == account.Id)
             });
 }
        public override Account Save(Account account)
        {
            var newAccount = account.Id == null;

              Account accountResult = this.AccountRepository.Save(account);

              var eventStore = new EventStore()
              {
            Date = DateTime.UtcNow,
            EventName = newAccount ? Events.CreateAccount : Events.UpdateAccount,
            Payload = account
              };

              if (newAccount)
              {
            this.eventStoreRepository.Add(eventStore);
              }
              else
              {
            this.eventStoreRepository.Add(eventStore);
              }

              return accountResult;
        }
 private Account Add(Account account)
 {
     return this.Update(account);
 }
 public Account Save(Account account)
 {
     var accountResult = account.Id == null ? this.Add(account) : this.Update(account);
       return accountResult;
 }
        private Account Update(Account account)
        {
            account.Id = account.ApiKey;
              dynamic item = new { account.Id, account.ApiKey, account.UserName, account.FullName, account.Password, account.Roles };

              string json = JsonConvert.SerializeObject(item, Formatting.Indented);
              File.WriteAllText(this.FilenameFromAccountName(account.ApiKey), json);
              return account;
        }
        private Account LoadFromFile(string filename)
        {
            if (File.Exists(filename))
            {
                string json = File.ReadAllText(filename);
                var item = JsonConvert.DeserializeObject<dynamic>(json);
            var account = new Account();
            account.ApiKey = item.ApiKey;
              account.UserName = item.UserName;
              account.FullName = item.FullName;
              account.Password = item.Password;
            account.Roles = (item.Roles != null) ? ((Newtonsoft.Json.Linq.JArray) item.Roles).Select(s => s.ToString()) : null;

            account.Id = account.ApiKey;

            return account;
            }

            return null;
        }
        public ActionResult Signup(SignupModel model)
        {
            if (_accountRepository.All().Any(p => p.UserName == model.Username)) {
            return Signup("Er bestaat al een gebruiker met dezelfde naam.");
              }

              if (string.IsNullOrEmpty(model.FullName) || string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Email)) {
            return Signup("Vul a.u.b. alle velden in.");
              }

              var account = new Account {
            FullName = model.FullName,
            UserName = model.Username,
            ApiKey = Guid.NewGuid().ToString(),
              };

              account.Password = account.ComputeSaltedHash("123");

              _accountRepository.Save(account);

              return null; //Login(account.Id, "", "~/Account");
        }
        public void MapTo(Account account, IQueryRepository queryRepository)
        {
            account.FullName = FullName;
            account.UserName = UserName;
            account.Email = Email;
            account.PhoneNumber = PhoneNumber;
            account.Notitie = Notitie;
            account.ApiKey = ApiKey;
            if (QueryAccess != null)
            {
                foreach (var queryAccessModel in QueryAccess)
                {
                    var query = queryRepository.GetByAlias(queryAccessModel.Alias);
                    if (queryAccessModel.View && query.ApiKeys.All(a => a != account.ApiKey))
                    {
                        query.ApiKeys.Add(account.ApiKey);
                        queryRepository.Save(query);
                    }
                    else if (!queryAccessModel.View && query.ApiKeys.Any(a => a == account.ApiKey))
                    {
                        query.ApiKeys.Remove(account.ApiKey);
                        queryRepository.Save(query);
                    }
                    if (queryAccessModel.Edit && !query.Authorization.Any(a => a.Operation == AuthorizationOperations.Edit && a.AccountId == account.Id))
                    {
                        query.Authorization.Add(new AuthorizationSettings { AccountId = account.Id, Operation = AuthorizationOperations.Edit });
                        queryRepository.Save(query);
                    }
                    else if (!queryAccessModel.Edit && query.Authorization.Any(a => a.Operation == AuthorizationOperations.Edit && a.AccountId == account.Id))
                    {
                        query.Authorization.Remove(query.Authorization.First(a => a.Operation == AuthorizationOperations.Edit && a.AccountId == account.Id));
                        queryRepository.Save(query);
                    }

                }
            }
        }
Ejemplo n.º 11
0
        public dynamic Post(string id, ExtendedAccountModel model)
        {
            if (string.IsNullOrEmpty(model.Id) || model.Id == Guid.Empty.ToString()) {
            model.ApiKey = Guid.NewGuid().ToString();
            model.Id = model.ApiKey;
              }

              var account = new Account();
              model.MapTo(account, _queryRepository);
              _accountRepository.Save(account);

              return Ok();
        }