public async Task <UserLoginResponse> Login(string MobileNo)
        {
            UserLoginResponse objResponse = new UserLoginResponse();

            try
            {
                using (var entities = new LiftBuddyEntities())
                {
                    var tblUser = new tblUser();
                    tblUser = entities.tblUsers.FirstOrDefault(e => e.MobileNo == MobileNo);
                    if (tblUser == null)
                    {
                        objResponse.IsRegistered = "No";
                        tblUser             = new tblUser();
                        tblUser.MobileNo    = MobileNo;
                        tblUser.CreatedDate = DateTime.Now;
                        tblUser.IsActive    = true;
                        entities.tblUsers.Add(tblUser);

                        await entities.SaveChangesAsync();
                    }
                    else
                    {
                        objResponse.IsRegistered = "Yes";
                    }

                    string OTP = await SendOTP(MobileNo);

                    if (!string.IsNullOrEmpty(OTP))
                    {
                        SaveOTP(OTP, MobileNo);
                        objResponse.Status        = true;
                        objResponse.UserId        = tblUser.ID;
                        objResponse.ResponseValue = "Otp Send Successfully";
                    }
                    else
                    {
                        objResponse.Status        = true;
                        objResponse.ResponseValue = "Unsuccessfull";
                    }
                }
            }
            catch (Exception ex)
            {
                objResponse.Status        = true;
                objResponse.ResponseValue = ex.Message;
            }
            return(objResponse);
        }
        public async Task <UserResponse> VerifyOTP(tblOtpTransaction objOTP)
        {
            UserResponse objResponse = new UserResponse();

            try
            {
                tblOtpTransaction verifyWith = new tblOtpTransaction();
                using (var entities = new LiftBuddyEntities())
                {
                    verifyWith = await Task.Run(() => entities.tblOtpTransactions.Where(o => o.MobileNo == objOTP.MobileNo).OrderByDescending(o => o.GenerateDateTime).FirstOrDefault());

                    if (objOTP.OTP == verifyWith.OTP)
                    {
                        verifyWith.IsUsed = true;
                        verifyWith.UsedOn = DateTime.Now;
                        await entities.SaveChangesAsync();

                        objResponse.Status = true;
                        objResponse.UserId = await Task.Run(() => entities.tblUsers.Where(o => o.MobileNo == objOTP.MobileNo).Select(o => o.ID).FirstOrDefault());

                        objResponse.ResponseValue = "OTP matched.";
                    }
                    else
                    {
                        objResponse.Status        = false;
                        objResponse.ResponseValue = "Otp mismatched.";
                        objResponse.UserId        = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                objResponse.Status        = false;
                objResponse.ResponseValue = ex.Message;
            }
            return(objResponse);
        }
        public async Task <Response> UpdateUserProfile(tblUser detail)
        {
            Response responseDetail = new Response();

            try
            {
                using (var entities = new LiftBuddyEntities())
                {
                    var tblUser = new tblUser();
                    tblUser = await Task.Run(() => entities.tblUsers.FirstOrDefault(s => s.ID == detail.UserId));

                    if (tblUser != null)
                    {
                        var    fileExtension = string.Empty;
                        var    fileName      = string.Empty;
                        string url           = string.Empty;
                        bool   ImageError    = false;
                        if (detail.RemoveProfilePic == true)
                        {
                            tblUser.ProfilePic = "";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(detail.fileName))
                            {
                                if (!detail.fileName.Contains("."))
                                {
                                    ImageError = true;
                                    responseDetail.ResponseValue = "Invalid File Name. Please send file name with extension.";
                                }
                                else
                                {
                                    var fileExt = detail.fileName.Split('.');
                                    if (fileExt.Length <= 0 || fileExt.Length > 2)
                                    {
                                        ImageError = true;
                                        responseDetail.ResponseValue = "Invalid File Name.";
                                    }
                                    else
                                    {
                                        fileName      = fileExt[0];
                                        fileExtension = fileExt[1];
                                    }
                                }
                                if (!string.IsNullOrEmpty(fileExtension))
                                {
                                    if (detail == null || string.IsNullOrEmpty(detail.fileBytes) || string.IsNullOrEmpty(detail.fileName) || string.IsNullOrEmpty(detail.fileBytes))
                                    {
                                        ImageError = true;
                                        responseDetail.ResponseValue = "Please send complete image detail.";
                                    }
                                    else
                                    {
                                        url = UploadImageCode(detail.fileBytes, fileName, fileExtension);
                                        tblUser.ProfilePic = url;
                                    }
                                }
                                else
                                {
                                    responseDetail.ResponseValue = "Invalid File Name. Please send file name with extension.";
                                    ImageError = true;
                                }
                            }
                        }

                        if (!ImageError)
                        {
                            if (!string.IsNullOrEmpty(detail.DobStr))
                            {
                                DateTime    Dob      = new DateTime();
                                CultureInfo provider = new CultureInfo("en-GB");
                                Dob         = DateTime.Parse(detail.DobStr, provider, DateTimeStyles.NoCurrentDateDefault);
                                tblUser.Dob = Dob;
                            }


                            tblUser.Gender = detail.Gender;

                            tblUser.UserName = detail.UserName;
                            tblUser.Name     = detail.Name;

                            await entities.SaveChangesAsync();

                            responseDetail.Status        = true;
                            responseDetail.ResponseValue = "Updated Successfully";
                        }
                    }
                    else
                    {
                        responseDetail.Status        = false;
                        responseDetail.ResponseValue = "User not found.";
                    }
                }
            }
            catch (Exception ex)
            {
                responseDetail.Status        = false;
                responseDetail.ResponseValue = ex.Message;
            }
            return(responseDetail);
        }
        public async Task <UserResponse> SaveProfileDetail(tblUser detail)
        {
            var    responseDetail = new UserResponse();
            var    fileExtension  = string.Empty;
            var    fileName       = string.Empty;
            var    tblUser        = new tblUser();
            string url            = string.Empty;

            if (!string.IsNullOrEmpty(detail.fileName))
            {
                if (!detail.fileName.Contains("."))
                {
                    responseDetail.ResponseValue = "Invalid File Name. Please send file name with extension.";
                }
                else
                {
                    var fileExt = detail.fileName.Split('.');
                    if (fileExt.Length <= 0 || fileExt.Length > 2)
                    {
                        responseDetail.ResponseValue = "Invalid File Name.";
                    }
                    else
                    {
                        fileName      = fileExt[0];
                        fileExtension = fileExt[1];
                    }
                }
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    if (detail == null || string.IsNullOrEmpty(detail.fileBytes) || string.IsNullOrEmpty(detail.fileName) || string.IsNullOrEmpty(detail.fileBytes))
                    {
                        responseDetail.ResponseValue = "Please send complete image detail.";
                    }
                    else
                    {
                        url = UploadImageCode(detail.fileBytes, fileName, fileExtension);
                    }
                }
            }

            try
            {
                using (var entities = new LiftBuddyEntities())
                {
                    tblUser = entities.tblUsers.FirstOrDefault(e => e.MobileNo == detail.MobileNo);
                    if (tblUser != null)
                    {
                        if (!string.IsNullOrEmpty(url))
                        {
                            tblUser.ProfilePic = url;
                        }
                        if (!string.IsNullOrEmpty(detail.Name))
                        {
                            tblUser.Name = detail.Name;
                            var username = detail.Name.Replace(' ', '_') + random.Next(0, 999999).ToString("D6");
                            tblUser.UserName = username;
                        }

                        responseDetail.UserId = tblUser.ID;
                    }
                    await entities.SaveChangesAsync();
                }
                responseDetail.ResponseValue = "Details updated successfully.";
                responseDetail.Status        = true;
            }
            catch (Exception e)
            {
                responseDetail.ResponseValue = e.Message;
            }

            return(responseDetail);
        }