Example #1
0
        public IActionResult CreateContact(Guid childId)
        {
            ChildCreateContactViewModel model = new ChildCreateContactViewModel()
            {
                ChildId = childId
            };

            return(View(model));
        }
Example #2
0
 public static Contact Create(ChildCreateContactViewModel model, string _userId)
 {
     return(new Contact()
     {
         Address = model.Address,
         CreatedById = _userId,
         Email = model.Email,
         FirstName = model.FirstName,
         LastName = model.LastName,
         Notes = model.Notes,
         PhoneHome = model.PhoneHome,
         PhoneMobile = model.PhoneMobile,
         PhoneWork = model.PhoneWork
     });
 }
Example #3
0
        public async Task <string> CreateContact(ChildCreateContactViewModel model)
        {
            if (ModelState.IsValid)
            {
                Contact contact = Contact.Create(model, _userId);
                await _unitOfWork.Contacts.Insert(contact);

                var contactResult = await _unitOfWork.SaveAsync();

                if (contactResult.Succeeded)
                {
                    PersonToContact personToContact = PersonToContact.Create(model.ChildId, contact.Id, _userId);
                    await _unitOfWork.PersonToContacts.Insert(personToContact);

                    var personToContactResult = await _unitOfWork.SaveAsync();

                    if (personToContactResult.Succeeded)
                    {
                        var guardian = await _unitOfWork.Users.GetOneAsync(x => x.Email == model.Email, include : x => x.Include(p => p.Person));

                        if (guardian != null)
                        {
                            PersonToChild personToChild = PersonToChild.Create(guardian.PersonId, model.ChildId, _userId);
                            await _unitOfWork.PersonToChildren.Insert(personToChild);

                            await _unitOfWork.SaveAsync();
                        }

                        var personToContacts = await _unitOfWork.PersonToContacts.GetAsync(x => x.IsActive && x.PersonId == model.ChildId,
                                                                                           include : x => x.Include(p => p.Contact));

                        var modelToView = Contact.Init(personToContacts.Select(x => x.Contact).ToList(), model.ChildId);
                        var htmlPage    = await RenderViewToString("EditChildContactInformation", modelToView);

                        return(htmlPage);
                    }
                }
            }
            return(await RenderViewToString("CreateContact", model));
        }