コード例 #1
0
        public async Task <Response> CheckUNValidity(int userId, string UserName)
        {
            Response responseDetail = new Response();

            try
            {
                using (var entities = new LiftBuddyEntities())
                {
                    var user = await Task.Run(() => entities.tblUsers.FirstOrDefault(e => e.ID != userId && e.UserName == UserName));

                    if (user != null)
                    {
                        responseDetail.ResponseValue = "UserName already exist.";
                        responseDetail.Status        = true;
                    }
                    else
                    {
                        responseDetail.ResponseValue = "Valid";
                        responseDetail.Status        = true;
                    }
                }
            }
            catch (Exception e)
            {
                responseDetail.ResponseValue = e.Message;
                responseDetail.Status        = false;
            }
            return(responseDetail);
        }
コード例 #2
0
        public async Task <UserResponse> GetVehicleTypeList()
        {
            UserResponse objResponse = new UserResponse();

            try
            {
                using (var entities = new LiftBuddyEntities())
                {
                    var list = await Task.Run(() => entities.spGetVehicleTypeList());

                    if (list == null)
                    {
                        objResponse.Status        = false;
                        objResponse.ResponseValue = "No Result FOund";
                    }
                    else
                    {
                        var serializer = new JavaScriptSerializer()
                        {
                            MaxJsonLength = 2147483647
                        };
                        objResponse.ResponseValue = serializer.Serialize(list);
                        objResponse.Status        = true;
                    }
                }
            }
            catch (Exception ex)
            {
                objResponse.Status        = false;
                objResponse.ResponseValue = ex.Message;
            }
            return(objResponse);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public async Task <UserResponse> GetUser(string MobileNo)
        {
            UserResponse objResponse = new UserResponse();

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

                    if (tblUser != null)
                    {
                        tblUser.UserId     = tblUser.ID;
                        objResponse.UserId = tblUser.ID;
                        if (tblUser.Dob != null)
                        {
                            tblUser.DobStr = String.Format("{0:dd MMMM yyyy}", tblUser.Dob);
                        }
                        if (!string.IsNullOrEmpty(tblUser.ProfilePic))
                        {
                            var serverPath = HttpContext.Current.Server.MapPath("~/UploadedImage");
                            var path       = Path.Combine(serverPath, tblUser.ProfilePic);
                            tblUser.ProfilePic = "http://" + System.Web.HttpContext.Current.Request.Url.Host + "/UploadedImage/" + tblUser.ProfilePic;
                            tblUser.fileBytes  = ImageToBase64(path);
                        }
                        objResponse.Status = true;
                        var serializer = new JavaScriptSerializer()
                        {
                            MaxJsonLength = 2147483647
                        };
                        objResponse.ResponseValue = serializer.Serialize(tblUser);
                    }
                    else
                    {
                        objResponse.Status        = false;
                        objResponse.ResponseValue = "User with Mobile no not found.";
                    }
                }
            }
            catch (Exception ex)
            {
                objResponse.Status        = false;
                objResponse.ResponseValue = ex.Message;
            }
            return(objResponse);
        }
コード例 #5
0
        private bool SaveOTP(string OTP, string MobileNo)
        {
            tblOtpTransaction objOtp = new tblOtpTransaction();

            objOtp.GenerateDateTime = DateTime.Now;
            objOtp.OTP      = OTP;
            objOtp.MobileNo = MobileNo;
            using (var entities = new LiftBuddyEntities())
            {
                try
                {
                    entities.tblOtpTransactions.Add(objOtp);
                    entities.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }