Ejemplo n.º 1
0
        public IHttpActionResult Delete(int id)
        {
            AccountQueries _accountQueries = new AccountQueries();
            Account        account         = _accountQueries.GetOneById(id);

            _accountQueries.Delete(account);
            return(Ok());
        }
Ejemplo n.º 2
0
        public IHttpActionResult Get(int id)
        {
            AccountQueries _accountQueries = new AccountQueries();
            var            account         = _accountQueries.GetOneById(id);
            AccountModel   accountModel    = new AccountModel();

            accountModel.Id   = account.Id;
            accountModel.Name = account.Name;

            foreach (var contact in account.Contacts)
            {
                ContactDetails contactDetails = new ContactDetails();
                contactDetails.Id        = contact.Id;
                contactDetails.FirstName = contact.FirstName;
                contactDetails.LastName  = contact.LastName;
                contactDetails.Email     = contact.Email;

                accountModel.Contacts.Add(contactDetails);
            }

            return(Ok(accountModel));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Put(int id, [FromBody] AccountModel accountModel)
        {
            if (ModelState.IsValid)
            {
                AccountQueries _accountQueries = new AccountQueries();
                Account        account         = _accountQueries.GetOneById(id);
                account.Name        = accountModel.Name;
                account.DateUpdated = DateTime.Now;
                foreach (var contactDetails in accountModel.Contacts)
                {
                    Contact contact = new Contact();
                    contact.Id        = contactDetails.Id;
                    contact.FirstName = contactDetails.FirstName;
                    contact.LastName  = contactDetails.LastName;
                    contact.Email     = contactDetails.Email;

                    account.Contacts.Add(contact);
                }

                _accountQueries.Save(account);
            }
            return(Ok());
        }