コード例 #1
0
        public IHttpActionResult GetAllMomentsWithLanguage()
        {
            List <MomentDetailsList> momentsList = new List <MomentDetailsList>();

            try
            {
                var objList = _momentsService.GetAllMoments().Where(a => a.ParentId == 0).ToList();
                foreach (var item in objList)
                {
                    MomentDetailsList details = new MomentDetailsList();
                    details.Message      = item.Message;
                    details.MomentId     = item.MomentId;
                    details.Name         = item.Name;
                    details.ParentId     = item.ParentId;
                    details.PosterUserId = item.PosterUserId;
                    details.PostingTime  = item.PostingTime;
                    if (string.IsNullOrEmpty(item.ImagePath))
                    {
                        details.ImagePath = noImagePath;
                    }
                    else
                    {
                        var extension = item.ImagePath.Split('.')[1];
                        var imageName = item.ImagePath.Split('.')[0] + "_thumbnail";
                        details.ImagePath = proImagePath + imageName + "." + extension;
                    }
                    // details.ImagePath = item.ImagePath == null ? noImagePath : item.ImagePath == string.Empty ? noImagePath : proImagePath + item.ImagePath;
                    var userLangDetails = _userLangService.GetLanguageListByUserId(item.PosterUserId);
                    if (userLangDetails != null)
                    {
                        var langDetails = _langService.GetLanguageDetailsById(userLangDetails.Learning_LanguageId);
                        if (langDetails != null)
                        {
                            details.LearningLangAbbrev = langDetails.Abbreviation;
                        }
                        langDetails = _langService.GetLanguageDetailsById(userLangDetails.Native_LanguageId);
                        if (langDetails != null)
                        {
                            details.NativeLangAbbrev = langDetails.Abbreviation;
                        }
                    }

                    if (item.UserUploadedId > 0)
                    {
                        var userUploads = _userUploadsService.GetUserUploadsById(item.UserUploadedId);
                        if (userUploads != null)
                        {
                            details.UploadedImage = userUploads.UploadedImagePath == null ? string.Empty : momentUploadImagePath + userUploads.UploadedImagePath;
                            details.UploadedAudio = userUploads.UploadedAudioPath == null ? string.Empty : momentUploadAudioPath + userUploads.UploadedAudioPath;
                        }
                    }

                    details.CountryImagePath = imagePath + item.Flag_Icon;
                    details.RepliesCount     = _momentsService.GetAllMomentsLIstByParentId(details.MomentId).Count;
                    details.FavouritesCount  = _favService.GetFavouritesListBymomentId(details.MomentId).Count;
                    momentsList.Add(details);
                }
            }
            catch (Exception e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, e.Message)));
            }

            return(Ok(momentsList));
        }
コード例 #2
0
        public IHttpActionResult Login(LoginViewModel model)
        {
            string            errorMessage = string.Empty;
            UserInfoViewModel obj          = new UserInfoViewModel();

            try
            {
                if (!ModelState.IsValid)
                {
                    errorMessage = String.Join(",", ErrorHelper.GetErrorListFromModelState(ModelState));

                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)));
                }
                bool isValidEmail = ValidateEmail(model.Email);
                if (!isValidEmail)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please give a valid email.")));
                }
                if (string.IsNullOrEmpty(model.Email))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Either First Name or Email or Phone is required.")));
                }

                var userDetails = _userService.GetUserDetailsByEmail(model.Email);
                if (userDetails != null)
                {
                    string salt           = userDetails.Password;
                    string hashedPassword = PasswordAndTrevoHelper.EncodePassword(model.Password, salt);
                    if (userDetails.PasswordHash != hashedPassword)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Password does not match.")));
                    }
                    obj.Email = userDetails.Email_Id;
                    if (string.IsNullOrEmpty(userDetails.ImagePath))
                    {
                        obj.ImagePath = noImagePath;
                    }
                    else
                    {
                        var extension = userDetails.ImagePath.Split('.')[1];
                        var imageName = userDetails.ImagePath.Split('.')[0] + "_thumbnail";
                        obj.ImagePath = proImagePath + imageName + "." + extension;
                    }
                    obj.IsVerified = userDetails.IsVerified;
                    obj.Name       = userDetails.Name;
                    obj.UserID     = userDetails.User_Id;
                    var userLangDetails = _userLanguageService.GetLanguageListByUserId(obj.UserID);
                    if (userLangDetails != null)
                    {
                        var langDetails = _langService.GetLanguageDetailsById(userLangDetails.Native_LanguageId);
                        if (langDetails != null)
                        {
                            obj.NativeLangugae = langDetails.Abbreviation;
                        }
                        langDetails = _langService.GetLanguageDetailsById(userLangDetails.Learning_LanguageId);
                        if (langDetails != null)
                        {
                            obj.LearningLanguage = langDetails.Abbreviation;
                        }
                    }
                    obj.FavMomentList = new List <long>();
                    var momentList = _favService.GetFavouritesListByUserId(userDetails.User_Id).Where(a => a.MomentId != 0).ToList();
                    foreach (var item in momentList)
                    {
                        obj.FavMomentList.Add(item.MomentId);
                    }
                }
                else
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User not found with the email.")));
                }
            }
            catch (System.Exception e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)));
            }
            return(Ok(obj));
        }
コード例 #3
0
        public IHttpActionResult GetUserDetailsById(RequestModel model)
        {
            UserWithCountryIconInfo userDetails = new UserWithCountryIconInfo();

            try
            {
                List <HobbiesDetails> hobbiesList = new List <HobbiesDetails>();
                hobbiesList = _hobbiesService.GetAllHobbies();
                if (string.IsNullOrEmpty(model.Id))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User Id is required.")));
                }
                long userId  = Convert.ToInt64(model.Id);
                var  details = _UserService.GetUserDetailsById(userId);
                if (details != null)
                {
                    userDetails.Address     = details.Address;
                    userDetails.Country_Id  = details.Country_Id;
                    userDetails.CreatedTime = details.CreatedTime;
                    userDetails.DeviceId    = details.DeviceId;
                    userDetails.Dob         = details.Dob;
                    userDetails.Email_Id    = details.Email_Id;
                    var countryDetails = _countryService.GetCountryDetailsById(details.Country_Id);
                    if (countryDetails != null)
                    {
                        userDetails.Flag_Icon = countryDetails.Flag_Icon;
                    }
                    userDetails.Gender    = details.Gender;
                    userDetails.Icon_Path = imagePath + countryDetails.Flag_Icon;
                }
                //userDetails.ImagePath = details.ImagePath == null ? noImagePath : details.ImagePath == string.Empty ? noImagePath : proImagePath + details.ImagePath;
                if (string.IsNullOrEmpty(details.ImagePath))
                {
                    userDetails.ImagePath = noImagePath;
                }
                else
                {
                    var extension = details.ImagePath.Split('.')[1];
                    var imageName = details.ImagePath.Split('.')[0] + "_thumbnail";
                    userDetails.ImagePath = proImagePath + imageName + "." + extension;
                }
                userDetails.Interests   = details.Interests;
                userDetails.IsVerified  = details.IsVerified;
                userDetails.LagLevel_ID = details.LagLevel_ID;
                var userLangDetails = _userLangService.GetLanguageListByUserId(details.User_Id);
                if (userLangDetails != null)
                {
                    var langDetails = _languageService.GetLanguageDetailsById(userLangDetails.Native_LanguageId);
                    userDetails.Native_LanguageId = userLangDetails.Native_LanguageId;
                    if (langDetails != null)
                    {
                        userDetails.NativeAbbrv = langDetails.Abbreviation;
                    }
                    langDetails = _languageService.GetLanguageDetailsById(userLangDetails.Learning_LanguageId);
                    userDetails.Learning_LanguageId = userLangDetails.Learning_LanguageId;
                    if (langDetails != null)
                    {
                        userDetails.LearningAbbrv = langDetails.Abbreviation;
                    }
                }
                userDetails.Name = details.Name;
                userDetails.Self_Introduction     = details.Self_Introduction;
                userDetails.TravelDestination_CId = details.TravelDestination_CId;
                userDetails.TrevoId = details.TrevoId;
                userDetails.User_Id = details.User_Id;

                var userHobbies = _hobbiesService.GetUserHobbiesByUserId(details.User_Id);
                foreach (var item in userHobbies)
                {
                    if (string.IsNullOrEmpty(userDetails.UserHobbies))
                    {
                        userDetails.UserHobbies = hobbiesList.Where(a => a.HobbiesId == item.HobbiesId).FirstOrDefault().Name;
                    }
                    else
                    {
                        userDetails.UserHobbies = userDetails.UserHobbies + " ," + hobbiesList.Where(a => a.HobbiesId == item.HobbiesId).FirstOrDefault().Name;
                    }
                }

                UserTransliterationDetails transliterationDetails = _transliterationService.GetTransliterationDetailsByUserId(userDetails.User_Id);
                if (transliterationDetails != null)
                {
                    userDetails.FavCount        = transliterationDetails.FavouritesCount;
                    userDetails.TTSCount        = transliterationDetails.TTSCount;
                    userDetails.SpellCheckCount = transliterationDetails.SpellCheckCount;
                    userDetails.TranslateCount  = transliterationDetails.TranslateCount;
                }
            }
            catch (Exception e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)));
            }
            return(Ok(userDetails));
        }