Example #1
0
        public IHttpActionResult UpdateProfile(UserProfileViewModel profile)
        {
            using (var db = new KiwiEntities())
            {
                if (profile.Id == 0)
                {
                    return(BadRequest("Invalid UserId"));
                }
                else
                {
                    var contact = db.Users
                                  .Where(x => x.Id == profile.Id)
                                  .Select(x => x.Contact).FirstOrDefault();

                    if (contact == null)
                    {
                        return(BadRequest("User Profile Not Found"));
                    }

                    contact.FirstName   = profile.FirstName;
                    contact.LastName    = profile.LastName;
                    contact.GenderId    = profile.GenderId;
                    contact.DateOfBirth = profile.DateOfBirth;

                    contact.Mobile   = profile.Mobile;
                    contact.Landline = profile.Landline;
                    contact.Email    = profile.Email;

                    contact.StreetNum = profile.StreetNum;
                    contact.Address   = profile.Address;
                    contact.Suburb    = profile.Suburb;
                    contact.City      = profile.City;
                    contact.Postcode  = profile.Postcode;
                    contact.Country   = profile.Country;

                    contact.BillingStreetNum = profile.BillingStreetNum;
                    contact.BillingAddress   = profile.BillingAddress;
                    contact.BillingSuburb    = profile.BillingSuburb;
                    contact.BillingCity      = profile.BillingCity;
                    contact.BillingPostcode  = profile.BillingPostcode;
                    contact.BillingCountry   = profile.BillingCountry;

                    contact.OscarNum   = profile.OscarNum;
                    contact.ReviewDate = profile.ReviewDate;

                    db.SaveChanges();
                    return(Ok(contact));
                }
            }
        }
Example #2
0
        public IHttpActionResult UpdateChildConditions(ChildMedicalConditionViewModel childProfile)
        {
            var currentUsername = User.Identity.GetUserName();

            using (var db = new KiwiEntities())
            {
                if (childProfile.Id == 0)
                {
                    var contact = new Contact();
                    contact.FirstName   = childProfile.FirstName;
                    contact.LastName    = childProfile.LastName;
                    contact.GenderId    = childProfile.GenderId;
                    contact.DateOfBirth = childProfile.DateOfBirth;
                    contact.IsActive    = true;
                    contact.CreatedOn   = DateTime.Now;
                    contact.CreatedBy   = currentUsername;
                    contact.UpdatedOn   = DateTime.Now;
                    contact.UpdatedBy   = currentUsername;

                    db.Contacts.Add(contact);
                    db.SaveChanges();

                    var child = new Child();
                    child.ContactId = contact.Id;
                    child.Name      = childProfile.FirstName + ' ' + childProfile.LastName;
                    child.KnownName = childProfile.KnownName;
                    child.IsActive  = true;
                    child.CreatedOn = DateTime.Now;
                    child.CreatedBy = currentUsername;
                    child.UpdatedOn = DateTime.Now;
                    child.UpdatedBy = currentUsername;

                    db.Children.Add(child);
                    db.SaveChanges();
                    return(Ok());
                }
                else
                {
                    var child = db.Children.Find(childProfile.Id);
                    if (child == null)
                    {
                        return(BadRequest("Child Not Found"));
                    }
                    child.Name      = childProfile.FirstName + ' ' + childProfile.LastName;
                    child.KnownName = childProfile.KnownName;
                    child.IsActive  = true;
                    child.UpdatedOn = DateTime.Now;
                    child.UpdatedBy = currentUsername;

                    var contact = child.Contact;
                    if (contact == null)
                    {
                        return(BadRequest("Child Not Found"));
                    }

                    contact.FirstName   = childProfile.FirstName;
                    contact.LastName    = childProfile.LastName;
                    contact.GenderId    = childProfile.GenderId;
                    contact.DateOfBirth = childProfile.DateOfBirth;
                    contact.IsActive    = true;
                    contact.UpdatedOn   = DateTime.Now;
                    contact.UpdatedBy   = currentUsername;

                    db.SaveChanges();
                    return(Ok());
                }
            }
        }