//Called when user grades a url
        public HttpResponseMessage Track(AnonUserChangeRequest model)
        {
            //If anonymous email used before
            if (_AnonTrackingService.SelectUserByEmail(model.Email) != null)
            {
                //If no current url cookie, then user is using a new session, increase visit count by 1
                if (model.Session == null)
                {
                    _AnonTrackingService.IncreaseVisitCount(model);
                }

                //If Url graded and stored before, increase Times Graded
                if (_AnonTrackingService.SelectUrlsByIdAndEmail(model) != null)
                {
                    try
                    {
                        _AnonTrackingService.IncreaseTimesGraded(model);
                        return(Request.CreateResponse(HttpStatusCode.OK, new SuccessResponse()));
                    }
                    catch (Exception ex)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                    }
                }
                // If url never graded, insert for current email
                else
                {
                    try
                    {
                        ItemResponse <int> resp = new ItemResponse <int>();
                        resp.Item = _AnonTrackingService.InsertUrl(model);
                        return(Request.CreateResponse(HttpStatusCode.OK, resp));
                    }
                    catch (Exception ex)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                    }
                }
            }

            //If Anonymous email never used, insert
            else
            {
                try
                {
                    ItemResponse <int> resp = new ItemResponse <int>();
                    resp.Item = _AnonTrackingService.InsertUser(model);
                    return(Request.CreateResponse(HttpStatusCode.OK, resp));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
 public HttpResponseMessage GetUrlsByUser(AnonUserChangeRequest model)
 {
     try
     {
         ItemsResponse <AnonUserUrls> response = new ItemsResponse <AnonUserUrls>();
         response.Items = _AnonTrackingService.SelectUrlsByUser(model);
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Esempio n. 3
0
        public string IncreaseVisitCount(AnonUserChangeRequest model)
        {
            string singleItem = "";

            this.DataProvider.ExecuteCmd("dbo.Anon_IncreaseVisitCount"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", model.Email);
            }
                                         , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                singleItem = reader.GetSafeString(0);
            });
            return(singleItem);
        }
Esempio n. 4
0
        public AnonUserUrls SelectUrlsByIdAndEmail(AnonUserChangeRequest model)
        {
            AnonUserUrls singleItem = null;

            DataProvider.ExecuteCmd("AnonUrl_SelectByIdAndEmail"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", model.Email);
                paramCollection.AddWithValue("@Url", model.Website);
            }
                                    , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                singleItem        = new AnonUserUrls();
                int startingIndex = 0;    //startingOrdinal
                singleItem.Url    = reader.GetSafeString(startingIndex++);
            });
            return(singleItem);
        }
Esempio n. 5
0
        public int InsertUser(AnonUserChangeRequest model)
        {
            int id = 0;

            DataProvider.ExecuteNonQuery("dbo.Anon_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", model.Email);
                paramCollection.AddWithValue("@VisitCount", 1);
                paramCollection.AddWithValue("@Url", model.Website);
                paramCollection.AddWithValue("@TimesGraded", 1);

                SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                idParameter.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(idParameter);
            }
                                         , returnParameters : delegate(SqlParameterCollection param)
            {
                Int32.TryParse(param["@Id"].Value.ToString(), out id);
            });
            return(id);
        }
Esempio n. 6
0
        public List <AnonUserUrls> SelectUrlsByUser(AnonUserChangeRequest model)
        {
            List <AnonUserUrls> list = new List <AnonUserUrls>();

            DataProvider.ExecuteCmd("dbo.AnonUrl_SelectByUser"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", model.Email);
            }
                                    , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                AnonUserUrls singleItem = new AnonUserUrls();
                int startingIndex       = 0; //startingOrdinal
                singleItem.Id           = reader.GetSafeInt32(startingIndex++);
                singleItem.IdOfEmail    = reader.GetSafeInt32(startingIndex++);
                singleItem.Url          = reader.GetSafeString(startingIndex++);
                singleItem.TimesGraded  = reader.GetSafeInt32(startingIndex++);
                singleItem.DateCreated  = reader.GetSafeDateTime(startingIndex++);
                singleItem.DateModified = reader.GetSafeDateTime(startingIndex++);
                list.Add(singleItem);
            });
            return(list);
        }