public UserApplicationData GetApplicationStatus(int applicationId)
 {
     using (UAS_SystemEntities dbContext = new UAS_SystemEntities())
     {
         try
         {
             UAS_Applicants retrivedApplication = dbContext.UAS_Applicants.SingleOrDefault(application => application.AplicantId == applicationId);
             if (retrivedApplication != null)
             {
                 return(new UserApplicationData()
                 {
                     ApplicationId = retrivedApplication.AplicantId,
                     ApplicationStatus = retrivedApplication.AppStatus
                 });
             }
             else
             {
                 return new UserApplicationData()
                        {
                        }
             };
         }
         catch (Exception e)
         {
             Console.WriteLine("Exception occured", e);
             return(null);
         }
     }
 }
        public async Task <UserMembersData> AddMember(UserMembersData member)
        {
            using (UAS_SystemEntities dbContext = new UAS_SystemEntities())
            {
                int result = 0;
                List <UAS_Family_Relations> relations     = new List <UAS_Family_Relations>();
                RelationsData[]             relationsData = member.RelationsList.ToArray();
                for (int i = 0; i < relationsData.Length && relationsData != null; i++)
                {
                    relations.Add(new UAS_Family_Relations()
                    {
                        RelativeName        = relationsData[i].RelativeName,
                        RelationId          = relationsData[i].RelativeId,
                        RelationType        = relationsData[i].RelationType,
                        ReverseRelationType = relationsData[i].ReverseRelationType
                    });
                }

                UAS_Household_Members members = new UAS_Household_Members()
                {
                    FirstName            = member.FirstName,
                    LastName             = member.LastName,
                    MiddleName           = member.MiddleName,
                    Dob                  = member.Dob,
                    Gender               = member.Gender,
                    Suffix               = member.Suffix,
                    UAS_Family_Relations = relations,
                    UserId               = member.UserId
                };
                try
                {
                    dbContext.Set <UAS_Household_Members>().Add(members);
                    result = await dbContext.SaveChangesAsync();

                    dbContext.Dispose();
                    if (result == 1)
                    {
                        return(member);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception", e);
                    return(null);
                }
                finally
                {
                    dbContext.Dispose();
                }
            }
        }
     public UserAccessData UserLogin(UserAccessData userDetails)
     {
         using (UAS_SystemEntities dbContext = new UAS_SystemEntities())
         {
             UAS_User_Details retrivedUser = dbContext.UAS_User_Details.SingleOrDefault(user => user.UserName == userDetails.UserName && user.Upassword == userDetails.Password);
             if (retrivedUser != null)
             {
                 return(new UserAccessData()
                 {
                     UserId = retrivedUser.UserId,
                     UserName = retrivedUser.UserName,
                     UserType = retrivedUser.UserType
                 });
             }
             else
             {
                 return new UserAccessData()
                        {
                        }
             };
         }
     }
 }
        public async Task <UserApplicationData> StoreApplication(UserApplicationData newApplication)
        {
            int result = 0;

            using (UAS_SystemEntities dbContext = new UAS_SystemEntities())
            {
                try
                {
                    dbContext.Set <UAS_Applicants>().Add(new UAS_Applicants()
                    {
                        AplicantId = newApplication.ApplicationId,
                        AppStatus  = newApplication.ApplicationStatus,
                        UserId     = newApplication.UserId
                    });
                    result = await dbContext.SaveChangesAsync();

                    dbContext.Dispose();
                    if (result == 1)
                    {
                        return(newApplication);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception occured", e);
                    return(null);
                }
                finally
                {
                    dbContext.Dispose();
                }
            }
        }
        public async Task <UserAccessData> UserSignup(UserAccessData loginDetails)
        {
            using (UAS_SystemEntities db = new UAS_SystemEntities())
            {
                int result = 0;
                UAS_User_Details signup = new UAS_User_Details();
                signup.UserName  = loginDetails.UserName;
                signup.UserType  = loginDetails.UserType;
                signup.Email     = loginDetails.Email;
                signup.Upassword = loginDetails.Password;
                try
                {
                    db.Set <UAS_User_Details>().Add(signup);
                    result = await db.SaveChangesAsync();

                    db.Dispose();
                    if (result == 1)
                    {
                        return(loginDetails);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception", e);
                    return(null);
                }
                finally
                {
                    db.Dispose();
                }
            }
        }