public ActionResult GetPersonalityQuestionById([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objPersonalityQuestions = from pq in _appDbContext.PersonalityQuestionaire
                                              where (pq.Id == Convert.ToInt32(objJson.SelectToken("Id")))
                                              select pq;

                if (objPersonalityQuestions == null || objPersonalityQuestions.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No result found." })));
                }

                return(Ok(new { Status = "OK", PersonalityQuestion = objPersonalityQuestions }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 2
0
        public ActionResult GetPollInfoById([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objGroupPoll = from gp in _appDbContext.GroupPoll
                                   where gp.Id == Convert.ToInt32(objJson.SelectToken("grouppollid"))
                                   select gp;

                if (objGroupPoll == null || objGroupPoll.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "GroupPoll " + Convert.ToString(objJson.SelectToken("grouppollid")) + " doesn’t exist" })));
                }

                return(Ok(new { Status = "OK", GroupPoll = objGroupPoll }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 3
0
        public ActionResult GetRandomJokes()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                Random objRandom = new Random();
                int    toSkip    = objRandom.Next(1, _appDbContext.Jokes.Count());

                var objJokes = (from j in _appDbContext.Jokes
                                orderby(objRandom.Next(j.Id))
                                select j).Skip(toSkip).Take(1);

                if (objJokes == null || objJokes.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No jocks available." })));
                }

                return(Ok(new { Status = "OK", Jokes = objJokes }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetAllActivities()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objActivities = (from a in _appDbContext.Activities
                                     select a);

                if (objActivities == null || objActivities.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No activities available." })));
                }

                return(Ok(new { Status = "OK", Activities = objActivities }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 5
0
        public ActionResult GetUserCalendarEventById([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserCalendarEvent = from uce in _appDbContext.UserCalendarEvent
                                           where uce.Id == Convert.ToInt32(objJson.SelectToken("usercalendareventid"))
                                           select uce;

                if (objUserCalendarEvent == null || objUserCalendarEvent.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Event doesn’t exist." })));
                }

                return(Ok(new { Status = "OK", CalendarEvent = objUserCalendarEvent }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 6
0
        public ActionResult GetActivitiesDetails([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }
                var objActivitiesDetails = _appDbContext.Activities.Select(s => s);

                if (objActivitiesDetails == null || objActivitiesDetails.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Data Not Found" })));
                }

                return(Ok(new { Status = "OK", User = objActivitiesDetails }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public async Task <ActionResult> UpdateUserCardInfo([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserCardInfoDetails = from uci in _appDbContext.UserCardInfo
                                             where (uci.Id == Convert.ToInt32(objJson.SelectToken("usercardinfoid")) && uci.UserId == strUserId)
                                             select uci;

                if (objUserCardInfoDetails.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Card info doesn’t exist or Invalid User." })));
                }

                clsAppCrypt objclsAppCrypt = new clsAppCrypt(configuration);

                UserCardInfo objUserCardInfo = new UserCardInfo();
                objUserCardInfo.Id              = Convert.ToInt32(objJson.SelectToken("usercardinfoid"));
                objUserCardInfo.NameOnCard      = Convert.ToString(objJson.SelectToken("nameoncard"));
                objUserCardInfo.CardNumber      = objclsAppCrypt.EncryptTripleDES(Convert.ToString(objJson.SelectToken("cardnumber")));
                objUserCardInfo.ExpiryDate      = Convert.ToString(objJson.SelectToken("expirydate"));
                objUserCardInfo.CardType        = Convert.ToString(objJson.SelectToken("cardtype"));
                objUserCardInfo.Issuer          = Convert.ToString(objJson.SelectToken("issuer"));
                objUserCardInfo.SecurityNumber  = objclsAppCrypt.EncryptTripleDES(Convert.ToString(objJson.SelectToken("securitynumber")));
                objUserCardInfo.LastUpdatedDate = DateTime.UtcNow;

                _appDbContext.UserCardInfo.Attach(objUserCardInfo);
                _appDbContext.Entry(objUserCardInfo).Property("NameOnCard").IsModified      = true;
                _appDbContext.Entry(objUserCardInfo).Property("CardNumber").IsModified      = true;
                _appDbContext.Entry(objUserCardInfo).Property("ExpiryDate").IsModified      = true;
                _appDbContext.Entry(objUserCardInfo).Property("CardType").IsModified        = true;
                _appDbContext.Entry(objUserCardInfo).Property("Issuer").IsModified          = true;
                _appDbContext.Entry(objUserCardInfo).Property("SecurityNumber").IsModified  = true;
                _appDbContext.Entry(objUserCardInfo).Property("LastUpdatedDate").IsModified = true;
                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Card Info Updated." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetAllPersonalityQuestions()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objPersonalityQuestions = _appDbContext.PersonalityQuestionaire.ToList();

                if (objPersonalityQuestions == null || objPersonalityQuestions.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No result found." })));
                }

                return(Ok(new { Status = "OK", PersonalityQuestion = objPersonalityQuestions }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 9
0
        public ActionResult GetUserCalendarEventsByMonth()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserCalendarEvent = from uce in _appDbContext.UserCalendarEvent
                                           where ((uce.EventDate >= Convert.ToDateTime(DateTime.UtcNow.ToString("yyyy-MM-dd")) && uce.EventDate < Convert.ToDateTime(DateTime.UtcNow.AddDays(30).ToString("yyyy-MM-dd"))) && uce.UserId == strUserId)
                                           orderby uce.EventDate, uce.EventTime
                select uce;

                if (objUserCalendarEvent.Count() <= 0)
                {
                    return(Ok(new { Status = "OK", Detail = "No events found." }));
                }

                return(Ok(new { Status = "OK", Detail = objUserCalendarEvent }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 10
0
        public ActionResult NotifyPollWhenEnded()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objGroupPollDetails = from gp in _appDbContext.GroupPoll
                                          where (gp.OwnerUserId == strUserId && gp.PollStatus == "active" && gp.EndDate <= DateTime.UtcNow)
                                          select gp;

                if (objGroupPollDetails.Count() <= 0)
                {
                    return(Ok(new { Status = "OK", Detail = "No data found." }));
                }

                return(Ok(new { Status = "OK", Detail = objGroupPollDetails }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult NotifyUserOnCardExpiry([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserCardInfo = _appDbContext.UserCardInfo
                                      .Where(uci => uci.UserId == strUserId).ToList <UserCardInfo>();

                if (objUserCardInfo.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Card info doesn’t exist." })));
                }

                clsAppCrypt objclsAppCrypt = new clsAppCrypt(configuration);

                List <UserCardInfo> lstExpiredCards = new List <UserCardInfo>();
                foreach (UserCardInfo objItem in objUserCardInfo)
                {
                    string[] strExpDateArr = objItem.ExpiryDate.Split("-");
                    if (strExpDateArr.Count() > 0)
                    {
                        int      lastDayOfMonth = DateTime.DaysInMonth(CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(Convert.ToInt32(strExpDateArr[1])), Convert.ToInt32(strExpDateArr[0]));
                        DateTime dtCardExpDate  = new DateTime(CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(Convert.ToInt32(strExpDateArr[1])), Convert.ToInt32(strExpDateArr[0]), lastDayOfMonth);
                        if (dtCardExpDate.AddDays(-Convert.ToInt32(objJson.SelectToken("remainingdays"))) < DateTime.UtcNow)
                        {
                            objItem.CardNumber     = objclsAppCrypt.DecryptTripleDES(objItem.CardNumber);
                            objItem.SecurityNumber = objclsAppCrypt.DecryptTripleDES(objItem.SecurityNumber);
                            lstExpiredCards.Add(objItem);
                            //return StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Your card is expired within " + Convert.ToString(objJson.SelectToken("remainingdays")) + " days." }));
                        }
                    }
                    else
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                    }
                }

                return(Ok(new { Status = "OK", UserExpiredCardInfo = lstExpiredCards }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult CheckCardExpiry([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                clsAppCrypt objclsAppCrypt = new clsAppCrypt(configuration);

                var objUserCardInfo = _appDbContext.UserCardInfo
                                      .Where(uci => uci.UserId == strUserId && objclsAppCrypt.DecryptTripleDES(uci.CardNumber).EndsWith(Convert.ToString(objJson.SelectToken("cardlast4digit"))))
                                      .OrderByDescending(t => t.Id).FirstOrDefault();

                if (objUserCardInfo == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Card info doesn’t exist." })));
                }

                string[] strExpDateArr = objUserCardInfo.ExpiryDate.Split("-");
                if (strExpDateArr.Count() > 0)
                {
                    DateTime dtCardExpDate = new DateTime(CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(Convert.ToInt32(strExpDateArr[1])), Convert.ToInt32(strExpDateArr[0]), 1);
                    if (dtCardExpDate.AddMonths(1) <= DateTime.UtcNow)
                    {
                        return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Your card is expired." })));
                    }
                    else
                    {
                        objUserCardInfo.CardNumber     = objclsAppCrypt.DecryptTripleDES(objUserCardInfo.CardNumber);
                        objUserCardInfo.SecurityNumber = objclsAppCrypt.DecryptTripleDES(objUserCardInfo.SecurityNumber);
                        return(Ok(new { Status = "OK", UserCardInfo = objUserCardInfo }));
                    }
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetListOfPlacesByGeoLocation([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strGoogleMapApiKey = Convert.ToString(configuration.GetSection("appSettings").GetSection("GoogleMapApiKey").Value);
                if (string.IsNullOrEmpty(strGoogleMapApiKey))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Google Map Api Key Missing" })));
                }

                int intRadius = 5000;
                if (!string.IsNullOrEmpty(Convert.ToString(objJson.SelectToken("radius"))))
                {
                    intRadius = Convert.ToInt32(objJson.SelectToken("radius"));
                }

                string     strRequestUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + Convert.ToString(objJson.SelectToken("latitude")) + "," + Convert.ToString(objJson.SelectToken("longitude")) + "&radius=" + Convert.ToString(intRadius) + "&type=" + Convert.ToString(objJson.SelectToken("placetype")) + "&key=" + strGoogleMapApiKey;
                WebRequest objWebRequest = WebRequest.Create(strRequestUrl);
                objWebRequest.Method = "GET";
                //objWebRequest.ContentType = "application/json";
                WebResponse  objWebResponse = objWebRequest.GetResponse();
                Stream       dataStream     = objWebResponse.GetResponseStream();
                StreamReader dataReader     = new StreamReader(dataStream);
                string       strResponse    = dataReader.ReadToEnd();
                dataReader.Close();
                dataStream.Close();
                objWebResponse.Close();

                if (string.IsNullOrEmpty(strResponse))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                return(Ok(new { Status = "OK", GoogleMapData = JObject.Parse(strResponse) }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 14
0
        public async Task <ActionResult> CreateUserCalendarEvent([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                UserCalendarEvent objUserCalendarEvent = new UserCalendarEvent();
                objUserCalendarEvent.UserId    = strUserId;
                objUserCalendarEvent.EventName = Convert.ToString(objJson.SelectToken("eventname"));
                objUserCalendarEvent.Location  = Convert.ToString(objJson.SelectToken("location"));
                objUserCalendarEvent.EventDate = Convert.ToDateTime(objJson.SelectToken("eventdate"));
                DateTime dt;
                if (!DateTime.TryParseExact(Convert.ToString(objJson.SelectToken("eventtime")), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    objUserCalendarEvent.EventTime = TimeSpan.Parse("00:00");
                }
                else
                {
                    objUserCalendarEvent.EventTime = dt.TimeOfDay;
                }
                objUserCalendarEvent.CreatedDate = DateTime.UtcNow;
                await _appDbContext.UserCalendarEvent.AddAsync(objUserCalendarEvent);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Calendar Event Created." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult MBTIPersonalitiesSummary([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strGroupName = "";

                var objUserPersonalitySummaryDetail = (from ups in _appDbContext.UserPersonalitySummary
                                                       where ups.UserId == strUserId
                                                       select ups).ToList <UserPersonalitySummary>();

                strGroupName = objUserPersonalitySummaryDetail[0].PrefferedMBTIMatch;

                if (string.IsNullOrEmpty(strGroupName))
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, (new { Status = "Error", Error = "Invalid MBT Match" })));
                }

                MBTIPersonalities objMBTIPersonalities = _appDbContext.MBTIPersonalities
                                                         .Where(mbt => mbt.Name == strGroupName).AsNoTracking().FirstOrDefault();

                if (objMBTIPersonalities == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Match is empty" })));
                }
                else
                {
                    return(Ok(new { Status = "OK", Description = objMBTIPersonalities.Description, Value1 = objMBTIPersonalities.Value1, Value2 = objMBTIPersonalities.Value2, Value3 = objMBTIPersonalities.Value3 }));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetUserCardInfoByUserId()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                clsAppCrypt objclsAppCrypt = new clsAppCrypt(configuration);

                var objUserCardInfo = from uci in _appDbContext.UserCardInfo
                                      where uci.UserId == strUserId
                                      select new
                {
                    Id              = uci.Id,
                    UserId          = uci.UserId,
                    NameOnCard      = uci.NameOnCard,
                    CardNumber      = objclsAppCrypt.DecryptTripleDES(uci.CardNumber),
                    ExpiryDate      = uci.ExpiryDate,
                    CardType        = uci.CardType,
                    Issuer          = uci.Issuer,
                    SecurityNumber  = objclsAppCrypt.DecryptTripleDES(uci.SecurityNumber),
                    AddedDate       = uci.AddedDate,
                    LastUpdatedDate = uci.LastUpdatedDate
                };

                if (objUserCardInfo == null || objUserCardInfo.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Card info doesn’t exist." })));
                }

                return(Ok(new { Status = "OK", UserCardInfo = objUserCardInfo }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetAllAnsweredPersonalityQuestions()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objPersonalityQuestions = from upqd in _appDbContext.UserPersonalityQuestionaireDetails
                                              join pq in _appDbContext.PersonalityQuestionaire on upqd.PersonalityQuestonId equals pq.Id into Details
                                              from pq1 in Details.DefaultIfEmpty()
                                              where (upqd.UserId == strUserId)
                                              select new
                {
                    UserId = upqd.UserId,
                    PersonalityQuestonId = upqd.PersonalityQuestonId,
                    PersonalityQAnswer   = upqd.PersonalityQAnswer,
                    PersonalityQuestion  = pq1.PersonalityQuestion,
                    Option1           = pq1.Option1,
                    Option2           = pq1.Option2,
                    Option3           = pq1.Option3,
                    Option4           = pq1.Option4,
                    MediaAssociatedId = pq1.MediaAssociatedId
                };

                if (objPersonalityQuestions == null || objPersonalityQuestions.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No result found." })));
                }

                return(Ok(new { Status = "OK", PersonalityQuestion = objPersonalityQuestions }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public async Task <ActionResult> AddUserCardInfo([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                clsAppCrypt objclsAppCrypt = new clsAppCrypt(configuration);

                UserCardInfo objUserCardInfo = new UserCardInfo();
                objUserCardInfo.UserId         = strUserId;
                objUserCardInfo.NameOnCard     = Convert.ToString(objJson.SelectToken("nameoncard"));
                objUserCardInfo.CardNumber     = objclsAppCrypt.EncryptTripleDES(Convert.ToString(objJson.SelectToken("cardnumber")));
                objUserCardInfo.ExpiryDate     = Convert.ToString(objJson.SelectToken("expirydate"));
                objUserCardInfo.CardType       = Convert.ToString(objJson.SelectToken("cardtype"));
                objUserCardInfo.Issuer         = Convert.ToString(objJson.SelectToken("issuer"));
                objUserCardInfo.SecurityNumber = objclsAppCrypt.EncryptTripleDES(Convert.ToString(objJson.SelectToken("securitynumber")));
                objUserCardInfo.AddedDate      = DateTime.UtcNow;
                await _appDbContext.UserCardInfo.AddAsync(objUserCardInfo);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Card Info Added." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 19
0
        public async Task <ActionResult> DeleteUserCalendarEventById([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                UserCalendarEvent objUserCalendarEvent = _appDbContext.UserCalendarEvent
                                                         .Where(uce => uce.Id == Convert.ToInt32(objJson.SelectToken("usercalendareventid")))
                                                         .FirstOrDefault();

                if (objUserCalendarEvent == null)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Event doesn’t exist." })));
                }
                else
                {
                    _appDbContext.UserCalendarEvent.Remove(objUserCalendarEvent);
                    int returnVal = await _appDbContext.SaveChangesAsync();

                    if (returnVal > 0)
                    {
                        return(Ok(new { Status = "OK", Detail = "Calendar Event Deleted." }));
                    }
                    else
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetRandomUnAnsweredPersonalityQuestion()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                Random objRandom = new Random();

                var objPersonalityQuestions = from pq in _appDbContext.PersonalityQuestionaire
                                              where !(
                    from upqd in _appDbContext.UserPersonalityQuestionaireDetails
                    where (upqd.UserId == strUserId)
                    select upqd.PersonalityQuestonId
                    ).Contains(pq.Id)
                                              orderby(objRandom.Next(pq.Id))
                                              select pq;

                if (objPersonalityQuestions == null || objPersonalityQuestions.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No result found." })));
                }

                return(Ok(new { Status = "OK", PersonalityQuestion = objPersonalityQuestions }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 21
0
        public async Task <ActionResult> AddSquareCustomerCardDetails([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objSquareCustomerData = _appDbContext.SquareCustomerDetails
                                            .Where(scd => scd.UserId == strUserId)
                                            .OrderByDescending(t => t.Id).FirstOrDefault();

                if (objSquareCustomerData == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Square customer details doesn’t exist." })));
                }

                string strSquareRequestUrl  = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareRequestUrl").Value);
                string strSquareAccessToken = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareAccessToken").Value);

                if (strSquareRequestUrl == "" || strSquareAccessToken == "")
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                string strSquareCustomerId = objSquareCustomerData.SquareCustomerId;

                string     strRequestUrl  = strSquareRequestUrl + "customers/" + strSquareCustomerId + "/cards";
                string     strRequestData = "{\"card_nonce\": \"" + Convert.ToString(objJson.SelectToken("card_nonce")) + "\",\"billing_address\": { \"address_line_1\": \"" + Convert.ToString(objJson.SelectToken("address_line_1")) + "\", \"address_line_2\": \"" + Convert.ToString(objJson.SelectToken("address_line_2")) + "\", \"locality\": \"" + Convert.ToString(objJson.SelectToken("locality")) + "\", \"administrative_district_level_1\": \"" + Convert.ToString(objJson.SelectToken("administrative_district_level_1")) + "\", \"postal_code\": \"" + Convert.ToString(objJson.SelectToken("postal_code")) + "\", \"country\": \"" + Convert.ToString(objJson.SelectToken("country")) + "\" }, \"cardholder_name\": \"" + Convert.ToString(objJson.SelectToken("cardholder_name")) + "\"}";
                WebRequest objWebRequest  = WebRequest.Create(strRequestUrl);
                objWebRequest.Method = "POST";
                byte[] byteArray;
                byteArray = Encoding.UTF8.GetBytes(strRequestData);
                objWebRequest.ContentType   = "application/json";
                objWebRequest.ContentLength = byteArray.Length;
                objWebRequest.Headers.Add("Authorization", "Bearer " + strSquareAccessToken);
                Stream dataStream = objWebRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
                WebResponse objWebResponse = objWebRequest.GetResponse();
                dataStream = objWebResponse.GetResponseStream();
                StreamReader dataReader  = new StreamReader(dataStream);
                string       strResponse = dataReader.ReadToEnd();
                dataReader.Close();
                dataStream.Close();
                objWebResponse.Close();

                if (string.IsNullOrEmpty(strResponse))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                string strSquareCustomerCardId = "";

                JObject objResponseJson = JObject.Parse(strResponse);
                if (objResponseJson.SelectToken("card") != null)
                {
                    strSquareCustomerCardId = Convert.ToString(objResponseJson.SelectToken("card").SelectToken("id"));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                if (Convert.ToBoolean(Convert.ToInt32(objJson.SelectToken("isprimary"))) == true)
                {
                    _appDbContext.SquareCustomerCardDetails.Where(x => x.UserId == strUserId).ToList().ForEach(x =>
                    {
                        x.IsPrimary = false;
                    });
                    await _appDbContext.SaveChangesAsync();
                }

                SquareCustomerCardDetails objSquareCustomerCardDetails = new SquareCustomerCardDetails();
                objSquareCustomerCardDetails.UserId               = strUserId;
                objSquareCustomerCardDetails.SquareCustomerId     = strSquareCustomerId;
                objSquareCustomerCardDetails.SquareCustomerCardId = strSquareCustomerCardId;
                objSquareCustomerCardDetails.IsPrimary            = Convert.ToBoolean(Convert.ToInt32(objJson.SelectToken("isprimary")));
                objSquareCustomerCardDetails.AddedDate            = DateTime.UtcNow;
                await _appDbContext.SquareCustomerCardDetails.AddAsync(objSquareCustomerCardDetails);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Customer card details added on square." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 22
0
        public async Task <ActionResult> DeleteAllSquareCustomerCardDetails()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strSquareRequestUrl  = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareRequestUrl").Value);
                string strSquareAccessToken = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareAccessToken").Value);

                if (strSquareRequestUrl == "" || strSquareAccessToken == "")
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                var objSquareCustomerCardDetails = _appDbContext.SquareCustomerCardDetails
                                                   .Where(sccd => sccd.UserId == strUserId).ToList <SquareCustomerCardDetails>();

                if (objSquareCustomerCardDetails.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Square customer card details doesn’t exist." })));
                }

                bool bnlErrorflag = false;
                foreach (SquareCustomerCardDetails objItem in objSquareCustomerCardDetails)
                {
                    string strSquareCustomerId     = objItem.SquareCustomerId;
                    string strSquareCustomerCardId = objItem.SquareCustomerCardId;

                    string     strRequestUrl = strSquareRequestUrl + "customers/" + strSquareCustomerId + "/cards/" + strSquareCustomerCardId;
                    WebRequest objWebRequest = WebRequest.Create(strRequestUrl);
                    objWebRequest.Method = "DELETE";
                    //objWebRequest.ContentType = "application/json";
                    objWebRequest.Headers.Add("Authorization", "Bearer " + strSquareAccessToken);
                    //Stream dataStream = objWebRequest.GetRequestStream();
                    //dataStream.Close();
                    WebResponse  objWebResponse = objWebRequest.GetResponse();
                    Stream       dataStream     = objWebResponse.GetResponseStream();
                    StreamReader dataReader     = new StreamReader(dataStream);
                    string       strResponse    = dataReader.ReadToEnd();
                    dataReader.Close();
                    dataStream.Close();
                    objWebResponse.Close();

                    JObject objResponseJson = JObject.Parse(strResponse);
                    if (objResponseJson.Count > 0)
                    {
                        //return StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" }));
                        bnlErrorflag = true;
                    }

                    _appDbContext.SquareCustomerCardDetails.Remove(objItem);
                    int returnVal = await _appDbContext.SaveChangesAsync();

                    if (returnVal <= 0)
                    {
                        bnlErrorflag = true;
                    }
                }
                if (bnlErrorflag == false)
                {
                    return(Ok(new { Status = "OK", Detail = "Customer all cards deleted on square." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Some cards are not deleted, Please try again." })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 23
0
        public async Task <ActionResult> DeleteSquareCustomerCardDetails([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strSquareRequestUrl  = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareRequestUrl").Value);
                string strSquareAccessToken = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareAccessToken").Value);

                if (strSquareRequestUrl == "" || strSquareAccessToken == "")
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                var objSquareCustomerCardDetails = _appDbContext.SquareCustomerCardDetails
                                                   .Where(sccd => sccd.UserId == strUserId && sccd.SquareCustomerCardId == Convert.ToString(objJson.SelectToken("squarecustomercardid")))
                                                   .OrderByDescending(t => t.Id).FirstOrDefault();

                if (objSquareCustomerCardDetails == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Square customer card details doesn’t exist." })));
                }

                string strSquareCustomerId     = objSquareCustomerCardDetails.SquareCustomerId;
                string strSquareCustomerCardId = objSquareCustomerCardDetails.SquareCustomerCardId;

                string     strRequestUrl = strSquareRequestUrl + "customers/" + strSquareCustomerId + "/cards/" + strSquareCustomerCardId;
                WebRequest objWebRequest = WebRequest.Create(strRequestUrl);
                objWebRequest.Method = "DELETE";
                //objWebRequest.ContentType = "application/json";
                objWebRequest.Headers.Add("Authorization", "Bearer " + strSquareAccessToken);
                //Stream dataStream = objWebRequest.GetRequestStream();
                //dataStream.Close();
                WebResponse  objWebResponse = objWebRequest.GetResponse();
                Stream       dataStream     = objWebResponse.GetResponseStream();
                StreamReader dataReader     = new StreamReader(dataStream);
                string       strResponse    = dataReader.ReadToEnd();
                dataReader.Close();
                dataStream.Close();
                objWebResponse.Close();

                JObject objResponseJson = JObject.Parse(strResponse);
                if (objResponseJson.Count > 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                _appDbContext.SquareCustomerCardDetails.Remove(objSquareCustomerCardDetails);
                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Customer card details deleted on square." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 24
0
        public ActionResult GetSquareCustomerCardDetailsByUserId()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strSquareRequestUrl  = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareRequestUrl").Value);
                string strSquareAccessToken = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareAccessToken").Value);

                if (strSquareRequestUrl == "" || strSquareAccessToken == "")
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                var objSquareCustomerDetails = _appDbContext.SquareCustomerDetails
                                               .Where(scd => scd.UserId == strUserId)
                                               .OrderByDescending(t => t.Id).FirstOrDefault();

                if (objSquareCustomerDetails == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Square customer details doesn’t exist." })));
                }

                string strSquareCustomerId = objSquareCustomerDetails.SquareCustomerId;

                string     strRequestUrl = strSquareRequestUrl + "customers/" + strSquareCustomerId;
                WebRequest objWebRequest = WebRequest.Create(strRequestUrl);
                objWebRequest.Method      = "GET";
                objWebRequest.ContentType = "application/json";
                objWebRequest.Headers.Add("Authorization", "Bearer " + strSquareAccessToken);
                //Stream dataStream = objWebRequest.GetRequestStream();
                //dataStream.Close();
                WebResponse  objWebResponse = objWebRequest.GetResponse();
                Stream       dataStream     = objWebResponse.GetResponseStream();
                StreamReader dataReader     = new StreamReader(dataStream);
                string       strResponse    = dataReader.ReadToEnd();
                dataReader.Close();
                dataStream.Close();
                objWebResponse.Close();

                if (string.IsNullOrEmpty(strResponse))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                JObject objResponseJson = JObject.Parse(strResponse);
                return(Ok(new { Status = "OK", SquareCustomerDetails = objResponseJson }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public async Task <ActionResult> UpdateSquareCustomerDetails([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strSquareRequestUrl  = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareRequestUrl").Value);
                string strSquareAccessToken = Convert.ToString(configuration.GetSection("appSettings").GetSection("SquareAccessToken").Value);

                if (strSquareRequestUrl == "" || strSquareAccessToken == "")
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                var objSquareCustomerData = _appDbContext.SquareCustomerDetails
                                            .Where(scd => scd.UserId == strUserId)
                                            .AsNoTracking().OrderByDescending(t => t.Id).FirstOrDefault();

                if (objSquareCustomerData == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Square customer details doesn’t exist." })));
                }

                string strSquareCustomerId = objSquareCustomerData.SquareCustomerId;

                string     strRequestUrl  = strSquareRequestUrl + "customers/" + strSquareCustomerId;
                string     strRequestData = "{\"given_name\": \"" + Convert.ToString(objJson.SelectToken("given_name")) + "\",\"family_name\": \"" + Convert.ToString(objJson.SelectToken("family_name")) + "\",\"email_address\": \"" + Convert.ToString(objJson.SelectToken("email_address")) + "\",\"address\": { \"address_line_1\": \"" + Convert.ToString(objJson.SelectToken("address_line_1")) + "\", \"address_line_2\": \"" + Convert.ToString(objJson.SelectToken("address_line_2")) + "\", \"locality\": \"" + Convert.ToString(objJson.SelectToken("locality")) + "\", \"administrative_district_level_1\": \"" + Convert.ToString(objJson.SelectToken("administrative_district_level_1")) + "\", \"postal_code\": \"" + Convert.ToString(objJson.SelectToken("postal_code")) + "\", \"country\": \"" + Convert.ToString(objJson.SelectToken("country")) + "\" }, \"phone_number\": \"" + Convert.ToString(objJson.SelectToken("phone_number")) + "\", \"reference_id\": \"" + Convert.ToString(objJson.SelectToken("reference_id")) + "\", \"note\": \"" + Convert.ToString(objJson.SelectToken("note")) + "\"}";
                WebRequest objWebRequest  = WebRequest.Create(strRequestUrl);
                objWebRequest.Method = "PUT";
                byte[] byteArray;
                byteArray = Encoding.UTF8.GetBytes(strRequestData);
                objWebRequest.ContentType   = "application/json";
                objWebRequest.ContentLength = byteArray.Length;
                objWebRequest.Headers.Add("Authorization", "Bearer " + strSquareAccessToken);
                Stream dataStream = objWebRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
                WebResponse objWebResponse = objWebRequest.GetResponse();
                dataStream = objWebResponse.GetResponseStream();
                StreamReader dataReader  = new StreamReader(dataStream);
                string       strResponse = dataReader.ReadToEnd();
                dataReader.Close();
                dataStream.Close();
                objWebResponse.Close();

                if (string.IsNullOrEmpty(strResponse))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                JObject objResponseJson = JObject.Parse(strResponse);
                if (objResponseJson.SelectToken("customer") == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }

                SquareCustomerDetails objSquareCustomerDetails = new SquareCustomerDetails();
                objSquareCustomerDetails.Id = Convert.ToInt32(objSquareCustomerData.Id);
                objSquareCustomerDetails.LastUpdatedDate = DateTime.UtcNow;

                _appDbContext.SquareCustomerDetails.Attach(objSquareCustomerDetails);
                _appDbContext.Entry(objSquareCustomerDetails).Property("LastUpdatedDate").IsModified = true;

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Customer details updated on square." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 26
0
        public async Task <ActionResult> UpdateUserCaledarEvent([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserCalendarEventDetails = from uce in _appDbContext.UserCalendarEvent
                                                  where (uce.Id == Convert.ToInt32(objJson.SelectToken("usercalendareventid")) && uce.UserId == strUserId)
                                                  select uce;

                if (objUserCalendarEventDetails.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Event doesn’t exist or Invalid User." })));
                }

                UserCalendarEvent objUserCalendarEvent = new UserCalendarEvent();
                objUserCalendarEvent.Id        = Convert.ToInt32(objJson.SelectToken("usercalendareventid"));
                objUserCalendarEvent.EventName = Convert.ToString(objJson.SelectToken("eventname"));
                objUserCalendarEvent.Location  = Convert.ToString(objJson.SelectToken("location"));
                objUserCalendarEvent.EventDate = Convert.ToDateTime(objJson.SelectToken("eventdate"));
                DateTime dt;
                if (!DateTime.TryParseExact(Convert.ToString(objJson.SelectToken("eventtime")), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    objUserCalendarEvent.EventTime = TimeSpan.Parse("00:00");
                }
                else
                {
                    objUserCalendarEvent.EventTime = dt.TimeOfDay;
                }
                objUserCalendarEvent.LastUpdatedDate = DateTime.UtcNow;

                _appDbContext.UserCalendarEvent.Attach(objUserCalendarEvent);
                _appDbContext.Entry(objUserCalendarEvent).Property("EventName").IsModified       = true;
                _appDbContext.Entry(objUserCalendarEvent).Property("Location").IsModified        = true;
                _appDbContext.Entry(objUserCalendarEvent).Property("EventDate").IsModified       = true;
                _appDbContext.Entry(objUserCalendarEvent).Property("EventTime").IsModified       = true;
                _appDbContext.Entry(objUserCalendarEvent).Property("LastUpdatedDate").IsModified = true;
                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Calendar Event Updated." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public ActionResult GetPersonalityMatchResult()
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objUserPersonalitySummaryDetail = (from ups in _appDbContext.UserPersonalitySummary
                                                       where ups.UserId == strUserId
                                                       select ups).ToList <UserPersonalitySummary>();

                if (objUserPersonalitySummaryDetail == null || objUserPersonalitySummaryDetail.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No users available." })));
                }

                var objUsers = (from u in _appDbContext.Users
                                select u);

                if (objUsers == null || objUsers.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No users available." })));
                }

                //Temp query for define structure
                var objUserPersonalitySummary = new List <PersonalityMatchResult>();

                /*(from ups in _appDbContext.UserPersonalitySummary
                 *                          join u in _appDbContext.Users on ups.UserId equals u.UserId into DetailsUsers
                 *                          from u1 in DetailsUsers.DefaultIfEmpty()
                 *                          join ula in _appDbContext.UserLoginAccount on ups.UserId equals ula.UserId into DetailsUserLoginAccount
                 *                          from ula1 in DetailsUserLoginAccount.DefaultIfEmpty()
                 *                          where 1 == 2
                 *                          select new { ups.UserId, ups.PrefferedMBTIMatch, u1.GeoLocationLatitude, u1.GeoLocationLongitude, u1.Age, ula1.CreatedDate }).ToList();*/

                if (objUsers.Count() < 1000)
                {
                    objUserPersonalitySummary = (from ups in _appDbContext.UserPersonalitySummary
                                                 join u in _appDbContext.Users on ups.UserId equals u.UserId into DetailsUsers
                                                 from u1 in DetailsUsers.DefaultIfEmpty()
                                                 join ula in _appDbContext.UserLoginAccount on ups.UserId equals ula.UserId into DetailsUserLoginAccount
                                                 from ula1 in DetailsUserLoginAccount.DefaultIfEmpty()
                                                 //where ups.UserId != strUserId && ups.PrefferedMBTIMatch.StartsWith(objUserPersonalitySummaryDetail[0].PrefferedMBTIMatch.Substring(0,3))
                                                 where ups.UserId != strUserId && ups.PrefferedMBTIMatch.Intersect(objUserPersonalitySummaryDetail[0].PrefferedMBTIMatch).Count() >= 3
                                                 select new PersonalityMatchResult()
                    {
                        UserId = ups.UserId,
                        PrefferedMBTIMatch = ups.PrefferedMBTIMatch,
                        GeoLocationLatitude = u1.GeoLocationLatitude,
                        GeoLocationLongitude = u1.GeoLocationLongitude,
                        Age = u1.Age,
                        CreatedDate = ula1.CreatedDate
                    }).ToList();
                }
                else if (objUsers.Count() >= 1000 && objUsers.Count() < 10000)
                {
                    objUserPersonalitySummary = (from ups in _appDbContext.UserPersonalitySummary
                                                 join u in _appDbContext.Users on ups.UserId equals u.UserId into DetailsUsers
                                                 from u1 in DetailsUsers.DefaultIfEmpty()
                                                 join ula in _appDbContext.UserLoginAccount on ups.UserId equals ula.UserId into DetailsUserLoginAccount
                                                 from ula1 in DetailsUserLoginAccount.DefaultIfEmpty()
                                                 //where ups.UserId != strUserId && ups.PrefferedMBTIMatch == objUserPersonalitySummaryDetail[0].PrefferedMBTIMatch
                                                 where ups.UserId != strUserId && ups.PrefferedMBTIMatch.Intersect(objUserPersonalitySummaryDetail[0].PrefferedMBTIMatch).Count() == 4
                                                 select new PersonalityMatchResult()
                    {
                        UserId = ups.UserId,
                        PrefferedMBTIMatch = ups.PrefferedMBTIMatch,
                        GeoLocationLatitude = u1.GeoLocationLatitude,
                        GeoLocationLongitude = u1.GeoLocationLongitude,
                        Age = u1.Age,
                        CreatedDate = ula1.CreatedDate
                    }).ToList();
                }

                //return Ok(new { Status = "OK", Count = objUserPersonalitySummary.Count(), MatchResult = objUserPersonalitySummary });

                var objLoginUser = objUsers.Where(t => t.UserId == strUserId).ToList();

                var objDistanceResult = from objItem in objUserPersonalitySummary
                                        select new PersonalityMatchResult()
                {
                    UserId               = objItem.UserId,
                    PrefferedMBTIMatch   = objItem.PrefferedMBTIMatch,
                    GeoLocationLatitude  = objItem.GeoLocationLatitude,
                    GeoLocationLongitude = objItem.GeoLocationLongitude,
                    Age         = objItem.Age,
                    CreatedDate = objItem.CreatedDate,
                    Distance    = Math.Ceiling(Math.Sqrt(
                                                   Math.Pow(111.2 * (objItem.GeoLocationLatitude - objLoginUser[0].GeoLocationLatitude), 2) +
                                                   Math.Pow(111.2 * (objLoginUser[0].GeoLocationLongitude - objItem.GeoLocationLongitude) * Math.Cos(objItem.GeoLocationLatitude / 57.3), 2)))
                };

                //Get 50 KM distance users
                objDistanceResult = objDistanceResult.Where(t => t.Distance <= 50);

                //Get users as per age
                if (objLoginUser[0].Age >= 20 && objLoginUser[0].Age <= 24)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 20 && t.Age <= 24));
                }
                else if (objLoginUser[0].Age >= 25 && objLoginUser[0].Age <= 29)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 25 && t.Age <= 29));
                }
                else if (objLoginUser[0].Age >= 30 && objLoginUser[0].Age <= 34)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 30 && t.Age <= 34));
                }
                else if (objLoginUser[0].Age >= 35 && objLoginUser[0].Age <= 39)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 35 && t.Age <= 39));
                }
                else if (objLoginUser[0].Age >= 40 && objLoginUser[0].Age <= 44)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 40 && t.Age <= 44));
                }
                else if (objLoginUser[0].Age >= 45 && objLoginUser[0].Age <= 49)
                {
                    objDistanceResult = objDistanceResult.Where(t => (t.Age >= 45 && t.Age <= 49));
                }

                //return Ok(new { Status = "OK", Count = objDistanceResult.Count(), MatchResult = objDistanceResult });

                var objUserActivities = (from ua in _appDbContext.UserActivities
                                         where ua.UserId == strUserId
                                         orderby ua.Rank
                                         select ua).Take(3).ToList <UserActivities>();

                if (objUserActivities == null || objUserActivities.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "No activity found." })));
                }

                var objMatchResult = new List <PersonalityMatchResult>();
                foreach (var objItem in objDistanceResult)
                {
                    var objUserActivitiesChild = (from ua in _appDbContext.UserActivities
                                                  where ua.UserId == objItem.UserId
                                                  orderby ua.Rank
                                                  select ua).Take(3).ToList <UserActivities>();

                    int recCount = objUserActivitiesChild.Select(t => t.ActivityId).Intersect(objUserActivities.Select(x => x.ActivityId)).Count();
                    if (recCount > 0)
                    {
                        objMatchResult.Add(objItem);
                    }
                }

                objMatchResult = objMatchResult.OrderBy(t => t.CreatedDate).Take(10).ToList();

                return(Ok(new { Status = "OK", Count = objMatchResult.Count(), MatchResult = objMatchResult }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public async Task <ActionResult> SaveUserPersonalityQuestionaireAnswers([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strMBTIType = GetMBTITypeByQuestionAnswer(Convert.ToInt32(objJson.SelectToken("personalityquestonid")), Convert.ToString(objJson.SelectToken("personalityqanswer")));

                if (strMBTIType == "")
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, (new { Status = "Error", Error = "Invalid Personality Queston Id" })));
                }

                UserPersonalityQuestionaireDetails objUserPersonalityQuestionaire = _appDbContext.UserPersonalityQuestionaireDetails
                                                                                    .Where(upqd => upqd.UserId == strUserId && upqd.PersonalityQuestonId == Convert.ToInt32(objJson.SelectToken("personalityquestonid")))
                                                                                    .OrderByDescending(t => t.Id).AsNoTracking().FirstOrDefault();

                int returnVal = 0;
                if (objUserPersonalityQuestionaire == null)
                {
                    UserPersonalityQuestionaireDetails objUserPersonalityQuestionaireDetails = new UserPersonalityQuestionaireDetails();
                    objUserPersonalityQuestionaireDetails.UserId = strUserId;
                    objUserPersonalityQuestionaireDetails.PersonalityQuestonId = Convert.ToInt32(objJson.SelectToken("personalityquestonid"));
                    objUserPersonalityQuestionaireDetails.PersonalityQAnswer   = Convert.ToString(objJson.SelectToken("personalityqanswer"));
                    objUserPersonalityQuestionaireDetails.MBTIType             = strMBTIType;
                    objUserPersonalityQuestionaireDetails.CreatedDate          = DateTime.UtcNow;
                    await _appDbContext.UserPersonalityQuestionaireDetails.AddAsync(objUserPersonalityQuestionaireDetails);

                    returnVal = await _appDbContext.SaveChangesAsync();
                }
                else
                {
                    UserPersonalityQuestionaireDetails objUserPersonalityQuestionaireDetails = new UserPersonalityQuestionaireDetails();
                    objUserPersonalityQuestionaireDetails.Id = objUserPersonalityQuestionaire.Id;
                    objUserPersonalityQuestionaireDetails.PersonalityQAnswer = Convert.ToString(objJson.SelectToken("personalityqanswer"));
                    objUserPersonalityQuestionaireDetails.MBTIType           = strMBTIType;
                    objUserPersonalityQuestionaireDetails.LastUpdated        = DateTime.UtcNow;

                    _appDbContext.UserPersonalityQuestionaireDetails.Attach(objUserPersonalityQuestionaireDetails);
                    _appDbContext.Entry(objUserPersonalityQuestionaireDetails).Property("PersonalityQAnswer").IsModified = true;
                    _appDbContext.Entry(objUserPersonalityQuestionaireDetails).Property("MBTIType").IsModified           = true;
                    _appDbContext.Entry(objUserPersonalityQuestionaireDetails).Property("LastUpdated").IsModified        = true;
                    returnVal = await _appDbContext.SaveChangesAsync();
                }

                if (returnVal > 0)
                {
                    var objUserPersonalityQuestionaireDetails = (from upqd in _appDbContext.UserPersonalityQuestionaireDetails
                                                                 where (upqd.UserId == strUserId)
                                                                 select upqd).ToList <UserPersonalityQuestionaireDetails>();

                    int E_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "E").Count());
                    int I_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "I").Count());
                    int S_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "S").Count());
                    int N_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "N").Count());
                    int T_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "T").Count());
                    int F_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "F").Count());
                    int J_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "J").Count());
                    int P_RawPointCount = Convert.ToInt32(objUserPersonalityQuestionaireDetails.Where(t => t.MBTIType == "P").Count());

                    int EI_ClarityVal = (E_RawPointCount > I_RawPointCount ? E_RawPointCount : I_RawPointCount);
                    int SN_ClarityVal = (S_RawPointCount > N_RawPointCount ? S_RawPointCount : N_RawPointCount);
                    int TF_ClarityVal = (T_RawPointCount > F_RawPointCount ? T_RawPointCount : F_RawPointCount);
                    int JP_ClarityVal = (J_RawPointCount > P_RawPointCount ? J_RawPointCount : P_RawPointCount);

                    string strPrefferedMBTIMatch = (E_RawPointCount > I_RawPointCount ? "E" : "I");
                    strPrefferedMBTIMatch += (S_RawPointCount > N_RawPointCount ? "S" : "N");
                    strPrefferedMBTIMatch += (T_RawPointCount > F_RawPointCount ? "T" : "F");
                    strPrefferedMBTIMatch += (J_RawPointCount > P_RawPointCount ? "J" : "P");

                    UserPersonalitySummary objUserPersonalitySummary = new UserPersonalitySummary();
                    objUserPersonalitySummary.UserId             = strUserId;
                    objUserPersonalitySummary.PrefferedMBTIMatch = strPrefferedMBTIMatch;
                    objUserPersonalitySummary.E_RawPoint         = E_RawPointCount;
                    objUserPersonalitySummary.I_RawPoint         = I_RawPointCount;
                    objUserPersonalitySummary.S_RawPoint         = S_RawPointCount;
                    objUserPersonalitySummary.N_RawPoint         = N_RawPointCount;
                    objUserPersonalitySummary.T_RawPoint         = T_RawPointCount;
                    objUserPersonalitySummary.F_RawPoint         = F_RawPointCount;
                    objUserPersonalitySummary.J_RawPoint         = J_RawPointCount;
                    objUserPersonalitySummary.P_RawPoint         = P_RawPointCount;
                    objUserPersonalitySummary.EI_Preference      = GetPreference(EI_ClarityVal, "EI");
                    objUserPersonalitySummary.EI_ClarityId       = EI_ClarityVal;
                    objUserPersonalitySummary.SN_Preference      = GetPreference(SN_ClarityVal, "SN");
                    objUserPersonalitySummary.SN_ClarityId       = SN_ClarityVal;
                    objUserPersonalitySummary.TF_Preference      = GetPreference(TF_ClarityVal, "TF");
                    objUserPersonalitySummary.TF_ClarityId       = TF_ClarityVal;
                    objUserPersonalitySummary.JP_Preference      = GetPreference(JP_ClarityVal, "JP");
                    objUserPersonalitySummary.JP_ClarityId       = JP_ClarityVal;
                    //objUserPersonalitySummary.CreatedDate = DateTime.UtcNow;

                    UserPersonalitySummary objUserPersonalitySummaryDetails = _appDbContext.UserPersonalitySummary
                                                                              .Where(ups => ups.UserId == strUserId)
                                                                              .AsNoTracking().FirstOrDefault();
                    if (objUserPersonalitySummaryDetails == null)
                    {
                        objUserPersonalitySummary.CreatedDate = DateTime.UtcNow;
                        await _appDbContext.UserPersonalitySummary.AddAsync(objUserPersonalitySummary);

                        returnVal = await _appDbContext.SaveChangesAsync();
                    }
                    else
                    {
                        objUserPersonalitySummary.LastUpdated = DateTime.UtcNow;

                        _appDbContext.UserPersonalitySummary.Attach(objUserPersonalitySummary);
                        _appDbContext.Entry(objUserPersonalitySummary).Property("PrefferedMBTIMatch").IsModified = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("E_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("I_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("S_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("N_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("T_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("F_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("J_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("P_RawPoint").IsModified         = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("EI_Preference").IsModified      = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("EI_ClarityId").IsModified       = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("SN_Preference").IsModified      = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("SN_ClarityId").IsModified       = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("TF_Preference").IsModified      = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("TF_ClarityId").IsModified       = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("JP_Preference").IsModified      = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("JP_ClarityId").IsModified       = true;
                        _appDbContext.Entry(objUserPersonalitySummary).Property("LastUpdated").IsModified        = true;
                        returnVal = await _appDbContext.SaveChangesAsync();
                    }

                    return(Ok(new { Status = "OK", Detail = "Answer saved." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
        public async Task <ActionResult> SaveUserActivity([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objActivities = (from a in _appDbContext.Activities
                                     where a.Id == Convert.ToInt32(objJson.SelectToken("activityid"))
                                     select a);

                if (objActivities == null || objActivities.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Activity not available." })));
                }

                var objUserActivitiesDetails = (from ua in _appDbContext.UserActivities
                                                where ua.UserId == strUserId
                                                orderby ua.Id descending
                                                select ua).ToList <UserActivities>();

                if (objUserActivitiesDetails.Where(t => t.ActivityId == Convert.ToInt32(objJson.SelectToken("activityid"))).Count() > 0)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "You already saved this activity." })));
                }

                int intRank = 1;
                if (objUserActivitiesDetails.Count() > 0)
                {
                    intRank = Convert.ToInt32(objUserActivitiesDetails[0].Rank) + 1;
                }

                UserActivities objUserActivities = new UserActivities();
                objUserActivities.UserId      = strUserId;
                objUserActivities.ActivityId  = Convert.ToInt32(objJson.SelectToken("activityid"));
                objUserActivities.Rank        = intRank;
                objUserActivities.CreatedDate = DateTime.UtcNow;
                await _appDbContext.UserActivities.AddAsync(objUserActivities);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Activity saved." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
Esempio n. 30
0
        public async Task <ActionResult> CreatePollForGroupEvent([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strUserId = UserLoginSessionKeys.GetUserIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strUserId))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objEvents = from e in _appDbContext.Events
                                where (e.Id == Convert.ToInt32(objJson.SelectToken("eventid")))
                                select e;

                if (objEvents.Count() <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Event doesn’t exist." })));
                }

                GroupPoll objGroupPoll = new GroupPoll();
                objGroupPoll.EventId = Convert.ToInt32(objJson.SelectToken("eventid"));
                //objGroupPoll.RestaurantName = Convert.ToString(objJson.SelectToken("restaurantname"));
                objGroupPoll.EventDate1 = Convert.ToDateTime(objJson.SelectToken("eventdate1"));
                DateTime dt;
                if (!DateTime.TryParseExact(Convert.ToString(objJson.SelectToken("eventtime1")), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    objGroupPoll.EventTime1 = TimeSpan.Parse("00:00");
                }
                else
                {
                    objGroupPoll.EventTime1 = dt.TimeOfDay;
                }
                objGroupPoll.EventDate2 = Convert.ToDateTime(objJson.SelectToken("eventdate2"));
                if (!DateTime.TryParseExact(Convert.ToString(objJson.SelectToken("eventtime2")), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    objGroupPoll.EventTime2 = TimeSpan.Parse("00:00");
                }
                else
                {
                    objGroupPoll.EventTime2 = dt.TimeOfDay;
                }
                objGroupPoll.StartDate   = DateTime.UtcNow;
                objGroupPoll.EndDate     = DateTime.UtcNow.AddHours(Convert.ToInt32(configuration.GetSection("appSettings").GetSection("PollEndHrs").Value));
                objGroupPoll.PollStatus  = "active";
                objGroupPoll.OwnerUserId = strUserId;
                //objGroupPoll.TiltCount = 0;
                objGroupPoll.CreatedDate = DateTime.UtcNow;
                await _appDbContext.GroupPoll.AddAsync(objGroupPoll);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Poll created." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }