public async Task<ActionResult> Edit(ContactViewModel model)
        {
            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0 && !validImageTypes.Contains(model.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }
            if (!ModelState.IsValid)
            {
                SqlQuery query = new SqlQuery
                {
                    Filter = "contact_id = " + model.Contact.Id
                };

                model.ContactInfos = (await databaseApi.GetRecordsAsync<ContactInfo>("contact_info", query)).Records;
                return View(model);
            }

            string result = await UploadImage(model.ImageUpload);
            if (result != null)
            {
                model.Contact.ImageUrl = DreamFactoryContext.BaseAddress + "/files/" + result;
            }

            await databaseApi.UpdateRecordsAsync("contact", new List<Contact> { model.Contact }, new SqlQuery());

            return RedirectToAction("List", Request.QueryString.ToRouteValues(new { GroupId = model.GroupId }));
        }
        public async Task<ActionResult> Details(int id)
        {
            SqlQuery query = new SqlQuery
            {
                Filter = "id = " + id,
                Related = "contact_info_by_contact_id"
            };

            Contact contact = (await databaseApi.GetRecordsAsync<Contact>("contact", query)).Records.FirstOrDefault();
            string imageData = string.Empty;
            if (!string.IsNullOrEmpty(contact.ImageUrl))
            {
                imageData = await filesApi.GetTextFileAsync(contact.ImageUrl.Split('/').Last());
            }

            ContactViewModel model = new ContactViewModel
            {
                Contact = contact,
                ContactInfos = contact.ContactInfos,
                ImageData = imageData
            };

            return View(model);
        }
        public async Task<ActionResult> Edit(int id, int? groupId)
        {
            SqlQuery query = new SqlQuery
            {
                Filter = "id = " + id,
                Related = "contact_info_by_contact_id"
            };

            Contact contact = (await databaseApi.GetRecordsAsync<Contact>("contact", query)).Records.FirstOrDefault();

            ContactViewModel model = new ContactViewModel
            {
                GroupId = groupId,
                Contact = contact,
                ContactInfos = contact.ContactInfos
            };

            return View(model);
        }