public IHttpActionResult UpdateUserDetails(UserDetailsModel model) { ReturnMsg obj = new ReturnMsg(); try { if (!ModelState.IsValid) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User Id is required."))); } TrevoUsers userDetails = new TrevoUsers(); userDetails.Address = model.Address == null ? string.Empty : model.Address; userDetails.Country_Id = model.Country_Id; userDetails.Email_Id = model.Email_Id == null ? string.Empty : model.Email_Id; userDetails.Name = model.Name == null ? string.Empty : model.Name; userDetails.Password = model.Password == null ? string.Empty : model.Password; userDetails.PasswordHash = model.PasswordHash == null ? string.Empty : model.PasswordHash; userDetails.QR_Code = model.QR_Code == null ? string.Empty : model.QR_Code; userDetails.Self_Introduction = model.Self_Introduction == null ? string.Empty : model.Self_Introduction; userDetails.TravelDestination_CId = model.TravelDestination_CId == null ? string.Empty : model.TravelDestination_CId; userDetails.TrevoId = model.TrevoId; userDetails.User_Id = model.User_Id; userDetails.CreatedTime = model.CreatedTime; userDetails.DeviceId = model.DeviceId == null?string.Empty:model.DeviceId; userDetails.Dob = model.Dob == null ? string.Empty : model.Dob; userDetails.ExternalAuthType = model.ExternalAuthType == null ? string.Empty : model.ExternalAuthType; userDetails.ExternalAuthUserId = model.ExternalAuthUserId == null ? string.Empty : model.ExternalAuthUserId; userDetails.Gender = model.Gender == null ? string.Empty : model.Gender; userDetails.ImagePath = model.ImagePath == null ? string.Empty : model.ImagePath; userDetails.Interests = model.Interests == null ? string.Empty : model.Interests; userDetails.IsVerified = model.IsVerified; userDetails.LagLevel_ID = model.LagLevel_ID; _userService.UpdateUserDetails(userDetails); obj.IsSuccess = true; obj.Message = "User Details updated successfully."; } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message))); } return(Ok(obj)); }
public IHttpActionResult GetUserDetailsByExternalAuthId(RequestModel model) { TrevoUsers userDetails = new TrevoUsers(); try { if (string.IsNullOrEmpty(model.Id)) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "External User Id is required."))); } userDetails = _UserService.GetUserDetailsByExternalAuthId(model.Id); if (userDetails == null) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User not found."))); } } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message))); } return(Ok(userDetails)); }
public IHttpActionResult ExternalAuthRegister(RegisterModel model) { ResponseModel obj = new ResponseModel(); string errorMessage = string.Empty; HttpResponseMessage response = new HttpResponseMessage(); try { if (!ModelState.IsValid) { errorMessage = String.Join(",", ErrorHelper.GetErrorListFromModelState(ModelState)); return(BadRequest(errorMessage)); } if (string.IsNullOrEmpty(model.ExternalAuthType)) { return(BadRequest("External Auth Type is required.")); } if (string.IsNullOrEmpty(model.ExternalAuthUserId)) { return(BadRequest("External Auth User Id is required.")); } bool isEmail = ValidateEmail(model.Email); if (isEmail == false) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Please give a valid email id."))); } var userDetailsByEmail = _userService.GetUserDetailsByEmail(model.Email); if (userDetailsByEmail == null) { } else { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "This email is already taken."))); } var trevoId = PasswordAndTrevoHelper.GenerateTrevoId(model.Name); TrevoUsers user = new TrevoUsers(); user.Address = model.Address == null ? string.Empty : model.Address; user.Country_Id = model.CountryId; user.DeviceId = model.DeviceId; user.Dob = model.Dob; user.Email_Id = model.Email; user.Gender = model.Gender; //user.UsersLanguageId = model.Id; user.Interests = model.Interests == null ? string.Empty : model.Interests; user.LagLevel_ID = model.LanguageLevelId; user.Name = model.Name; user.Password = string.Empty; user.PasswordHash = string.Empty; user.QR_Code = string.Empty; user.Self_Introduction = model.SelfIntroduction == null ? string.Empty : model.SelfIntroduction; user.TravelDestination_CId = model.TravelDestination == null ? string.Empty : model.TravelDestination; user.TrevoId = trevoId; user.IsVerified = 0; user.ImagePath = string.Empty; user.CreatedTime = DateTime.UtcNow; user.ExternalAuthType = model.ExternalAuthType; user.ExternalAuthUserId = model.ExternalAuthUserId; //_userService.InsertUserDetails(user); //insert the user language first var isSuccess = _userService.InsertUserDetails(user); if (isSuccess.IsSuccess) { UsersLanguage userLanguage = new UsersLanguage(); userLanguage.User_Id = Convert.ToInt64(isSuccess.Message); obj.UserID = userLanguage.User_Id; userLanguage.Learning_LanguageId = model.LearningLanguageId; userLanguage.Native_LanguageId = model.NativeLanguageId; _userLanguageService.InsertUserLanguageDetails(userLanguage); } else { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There is some error."))); } //send mail after successfull registration StreamReader reader = new StreamReader(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/EmailTemplate/RegistrationActivation.html")); string readFile = reader.ReadToEnd(); string mailBody = ""; mailBody = readFile; mailBody = mailBody.Replace("$$UserName$$", model.Name); string otpCode = PasswordAndTrevoHelper.CreateRandomNumber(5); string encryptedUserName = SSTCryptographer.Encrypt(model.Name, SSTCryptographer.Key = "Activation"); mailBody = mailBody.Replace(" $$OTPCode$$", otpCode); ReturnMsg mailResult = SendMail.SendEmail(InfoMail, model.Email, "Account Activation", mailBody); obj.Email = model.Email; obj.Name = model.Name; } catch (System.Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message))); } return(Ok(obj)); }
public ReturnMsg InsertUserDetails(TrevoUsers details) { ReturnMsg obj = new ReturnMsg(); List <SqlParameter> sp = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@name", Value = details.Name, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@email_Id", Value = details.Email_Id, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@password", Value = details.Password, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@dob", Value = details.Dob, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@gender", Value = details.Gender, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@deviceId ", Value = details.DeviceId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@trevoId", Value = details.TrevoId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@self_introduction", Value = details.Self_Introduction, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@countryId ", Value = details.Country_Id, SqlDbType = SqlDbType.BigInt }, new SqlParameter() { ParameterName = "@address ", Value = details.Address, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@qrCode", Value = details.QR_Code, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@interests", Value = details.Interests, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@travelDestinationCid", Value = details.TravelDestination_CId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@lagLevelId", Value = details.LagLevel_ID, SqlDbType = SqlDbType.BigInt }, new SqlParameter() { ParameterName = "@passwordHash", Value = details.PasswordHash, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@isVerified", Value = details.IsVerified, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@imagePath", Value = details.ImagePath, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@createdTime", Value = details.CreatedTime, SqlDbType = SqlDbType.DateTime }, new SqlParameter() { ParameterName = "@externalAuthType", Value = details.ExternalAuthType, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@externalAuthUserId", Value = details.ExternalAuthUserId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@id", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output }, }; object[] parameters = sp.ToArray(); List <object> pa = new List <object>(); _userRepository.ExecuteStoredProcedureForOutParams(PROC_INSERT_USER_DETAILS, out pa, parameters); if (pa.Count > 0) { obj.IsSuccess = true; obj.Message = pa[0]; } else { obj.IsSuccess = false; } return(obj); }
public ReturnMsg UpdateUserDetails(TrevoUsers details) { ReturnMsg msg = new ReturnMsg(); try { List <SqlParameter> sp = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@name", Value = details.Name, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@email_Id", Value = details.Email_Id, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@password", Value = details.Password, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@dob", Value = details.Dob, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@gender", Value = details.Gender, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@deviceId ", Value = details.DeviceId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@trevoId", Value = details.TrevoId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@self_introduction", Value = details.Self_Introduction, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@countryId ", Value = details.Country_Id, SqlDbType = SqlDbType.BigInt }, new SqlParameter() { ParameterName = "@address ", Value = details.Address, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@qrCode", Value = details.QR_Code, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@interests", Value = details.Interests, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@travelDestinationCid", Value = details.TravelDestination_CId, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@lagLevelId", Value = details.LagLevel_ID, SqlDbType = SqlDbType.BigInt }, new SqlParameter() { ParameterName = "@userId", Value = details.User_Id, SqlDbType = SqlDbType.BigInt }, new SqlParameter() { ParameterName = "@isVerified", Value = details.IsVerified, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@imagePath", Value = details.ImagePath, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@createdTime", Value = details.CreatedTime, SqlDbType = SqlDbType.DateTime }, new SqlParameter() { ParameterName = "@passwordHash", Value = details.PasswordHash, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@externalAuthType", Value = details.ExternalAuthType, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@externalAuthUserId", Value = details.ExternalAuthUserId, SqlDbType = SqlDbType.VarChar }, }; object[] parameters = sp.ToArray(); _userRepository.ExecuteStoredProcedure(PROC_UPDATE_USER_DETAILS, parameters); msg.IsSuccess = true; } catch (Exception e) { msg.IsSuccess = false; msg.Message = e.Message; } return(msg); }
public async Task <IHttpActionResult> UploadUserProfileImage() { ReturnMsg msg = new ReturnMsg(); if (!Request.Content.IsMimeMultipartContent()) { return(Content(HttpStatusCode.BadRequest, "Unsupported media type.")); } try { string root = HttpContext.Current.Server.MapPath("~/ProfileImages"); var provider = new MultipartFormDataStreamProvider(root); await Request.Content.ReadAsMultipartAsync(provider); string StoragePath = HttpContext.Current.Server.MapPath("~/ProfileImages/OriginalSize"); TrevoUsers userDetails = new TrevoUsers(); if (provider.FormData.Count == 0) { File.Delete(provider.FileData[0].LocalFileName); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User Id is required."))); } long userId = Convert.ToInt64(provider.FormData.GetValues(0)[0]); //userDetails.UserID =provider.FormData.GetValues(0)[0]; //moving the file to the required destination string temp = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string fileName1 = string.Empty; string path1 = string.Empty; foreach (MultipartFileData fileData in provider.FileData) { string fileName = fileData.Headers.ContentDisposition.FileName; if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) { fileName = fileName.Trim('"'); } if (fileName.Contains(@"/") || fileName.Contains(@"\")) { fileName = Path.GetFileName(fileName); } string extension = fileName.Split('.')[1]; if (extension.ToLower() != "jpg" && extension.ToLower() != "jpeg" && extension.ToLower() != "png") { File.Delete(fileData.LocalFileName); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Please upload a file with extension in jpg or jpeg or png."))); } fileName1 = fileName.Split('.')[0] + "_" + temp + "." + extension; path1 = Path.Combine(StoragePath, fileName1); File.Move(fileData.LocalFileName, path1); File.Delete(fileData.LocalFileName); //saving the file in medium size; int width = 0; string folderName = string.Empty; width = 400; //Saving the medium size folderName = "ProfileImages"; ImageUploadHelper imageUpload = new ImageUploadHelper { Width = width }; ImageResult imageResult = imageUpload.RenameUploadFile(fileData, true, "", fileName1, folderName); //saving the file in thumbnail size width = 150; imageUpload = new ImageUploadHelper { Width = width }; imageResult = imageUpload.RenameUploadFile(fileData, false, "", fileName1, folderName); } var user = _UserService.GetUserDetailsById(userId); if (user != null) { msg = _UserService.UpdateUserProfileImage(fileName1, user.User_Id); if (!msg.IsSuccess) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There is some error"))); } else { msg.IsSuccess = true; msg.Message = "Your profile image is successfully updated."; } } else { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found."))); } } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, e.Message))); } return(Ok(msg)); }