コード例 #1
0
        public async Task <bool> Delete(int companyId, string username)
        {
            //-- Connects to the database
            using (var entity = new CompanyBrokerAccountEntities())
            {
                //-- fetches an account based on the informations
                var account = entity.CompanyAccounts.Where(a => a.CompanyId == companyId && a.Username == username).Single <CompanyAccount>();
                //-- checks the account
                if (account != null)
                {
                    //-- removes the account
                    entity.CompanyAccounts.Remove(account);
                    //-- informs of the state
                    entity.Entry(account).State = EntityState.Deleted;
                    //-- saves the state
                    await entity.SaveChangesAsync();

                    //-- return
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #2
0
        public async Task <bool> PUT(AccountRequest AccountAPIModel)
        {
            //-- Getting access to the
            using (var entity = new CompanyBrokerAccountEntities())
            {
                //-- fetches the account
                var responsData = entity.CompanyAccounts.Where(a => a.CompanyId == AccountAPIModel.CompanyId && a.Username == AccountAPIModel.Username).Single <CompanyAccount>();
                //-- checks the account
                if (responsData != null)
                {
                    //-- sets the new informations
                    responsData.Email    = AccountAPIModel.Email;
                    responsData.Active   = AccountAPIModel.Active;
                    responsData.Username = AccountAPIModel.Username;

                    //-- checks if password has been changed
                    if (!string.IsNullOrEmpty(AccountAPIModel.Password))
                    {
                        //-- creates new salt
                        var newSalt = GenerateSalt(32);
                        //-- sets new password informations
                        responsData.PasswordHash = GetHash(AccountAPIModel.Password, newSalt);
                        responsData.PasswordSalt = newSalt;
                    }
                    //-- Sets the data entry and sate
                    entity.Entry(responsData).State = EntityState.Modified;
                    //-- saves the data
                    await entity.SaveChangesAsync();

                    //-- returns
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }