Esempio n. 1
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));
        }
Esempio n. 2
0
        public IHttpActionResult GetfavouritesListByUserId(RequestModel model)
        {
            List <FavouritesModel> returnObj = new List <FavouritesModel>();

            try
            {
                if (string.IsNullOrEmpty(model.Id))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User Id is required.")));
                }
                long id      = Convert.ToInt64(model.Id);
                var  favList = _favService.GetFavouritesListByUserId(id).ToList();
                foreach (var item in favList)
                {
                    FavouritesModel details = new FavouritesModel();
                    details.FavouritesId       = item.FavouritesId;
                    details.FavouritesUserName = item.FavouritesUserName;
                    details.FavouriteUserId    = item.FavouriteUserId;
                    details.IsSender           = item.IsSender;
                    if (item.MomentId == 0 && item.Message.Contains(','))
                    {
                        details.IsCorrected     = 1;
                        details.IncorrectedText = item.Message.Split(',')[0];
                        details.CorrectedText   = item.Message.Split(',')[1];
                    }
                    else
                    {
                        details.Message = item.Message;
                    }
                    details.LocalMessageId     = Convert.ToInt32(item.LocalMessageId);
                    details.MomentId           = item.MomentId;
                    details.SenderRecieverId   = item.SenderRecieverId;
                    details.SenderRecieverName = item.SenderRecieverName;
                    if (!string.IsNullOrEmpty(item.AddedDate))
                    {
                        int    index = item.AddedDate.LastIndexOf("/");
                        string date  = item.AddedDate.Substring(0, index + 3);
                        details.AddedDate = date;
                    }
                    else
                    {
                        details.AddedDate = item.AddedDate;
                    }
                    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 = proImagePath + item.ImagePath;
                    var countryDetails = _countryService.GetCountryDetailsById(item.CountryId);
                    if (countryDetails != null)
                    {
                        details.Icon_Path = imagePath + countryDetails.Flag_Icon;
                    }
                    returnObj.Add(details);
                }
            }
            catch (Exception e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)));
            }

            return(Ok(returnObj));
        }