示例#1
0
        public CreateUpdateNoteResponse UpdateNote([FromBody] UpdateNoteAction updateNote)
        {
            CreateUpdateNoteResponse response = new CreateUpdateNoteResponse();

            response.Status = string.Empty;

            if (string.IsNullOrEmpty(updateNote.Email))
            {
                return(response);
            }
            using (RequestTracker request = new RequestTracker(Constant.RequestAPI.UpdateNote.ToString(), updateNote.Email))
            {
                try
                {
                    if (string.IsNullOrEmpty(updateNote.Email) ||
                        string.IsNullOrEmpty(updateNote.AuthToken) ||
                        string.IsNullOrEmpty(updateNote.NoteContents) ||
                        string.IsNullOrEmpty(updateNote.RowKey))
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        return(response);
                    }
                    if (updateNote.NoteContents.Length > Constant.MaxNoteLength)
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        response.Status  = "TooLong";
                        return(response);
                    }
                    // Use the email and authToken to get the userId
                    string userId = UserController.GetUserId(updateNote.Email, updateNote.AuthToken);
                    if (string.IsNullOrEmpty(userId))
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        // Expired AuthToken
                        response.Status = "Expired";
                        return(response);
                    }
                    response.Note = NoteModel.UpdateNote(userId, updateNote.RowKey, updateNote.NoteContents, updateNote.City, updateNote.Latitude, updateNote.Longitude, updateNote.Completed);
                    if (response.Note == null)
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        // Expired AuthToken
                        response.Status = "Invalid";
                        return(response);
                    }
                    LastUpdateModel.SetLastUpdate(userId);
                    response.Status = "Success";
                    return(response);
                }
                catch (Exception e)
                {
                    request.response = RequestTracker.RequestResponse.ServerError;
                    ExceptionTracker.LogException(e);
                    return(response);
                }
            }
        }
示例#2
0
        // GET: LastUpdateTime
        // Used to force refresh of client
        public long LastUpdateTime()
        {
            LastUpdateModel lastUpdated = Database.GetLastUpdateTime().Result;

            if (lastUpdated == null)
            {
                return(0);
            }

            return(lastUpdated.time.Ticks);
        }
示例#3
0
        private async Task SetLastUpdateAsync()
        {
            var lastUpdateModel = new LastUpdateModel {
                lastUpdate = Convert.ToInt32(Math.Floor(DateTimeOffset.Now.ToUnixTimeMilliseconds() / 1000.0))
            };

            using var client = new AmazonDynamoDBClient();
            var key  = GetKey("LAST_UPDATE", "LAST_UPDATE");
            var item = key.ToDictionary(x => x.Key, x => x.Value);

            item.Add("data", new AttributeValue {
                S = JsonSerializer.Serialize(lastUpdateModel)
            });
            var putItemRequest = new PutItemRequest(TABLE_NAME, item);

            _ = await client.PutItemAsync(putItemRequest);
        }
示例#4
0
 public string DeleteNote([FromBody] DeleteNoteAction deleteNote)
 {
     if (string.IsNullOrEmpty(deleteNote.Email))
     {
         return(string.Empty);
     }
     using (RequestTracker request = new RequestTracker(Constant.RequestAPI.DeleteNote.ToString(), deleteNote.Email))
     {
         try
         {
             if (string.IsNullOrEmpty(deleteNote.Email) ||
                 string.IsNullOrEmpty(deleteNote.AuthToken) ||
                 string.IsNullOrEmpty(deleteNote.RowKey))
             {
                 request.response = RequestTracker.RequestResponse.UserError;
                 return(string.Empty);
             }
             // Use the email and authToken to get the userId
             string userId = UserController.GetUserId(deleteNote.Email, deleteNote.AuthToken);
             if (string.IsNullOrEmpty(userId))
             {
                 request.response = RequestTracker.RequestResponse.UserError;
                 // Expired AuthToken
                 return("Expired");
             }
             if (!NoteModel.DeleteNote(userId, deleteNote.RowKey))
             {
                 return("Invalid");
             }
             LastUpdateModel.SetLastUpdate(userId);
             return("Success");
         }
         catch (Exception e)
         {
             request.response = RequestTracker.RequestResponse.ServerError;
             ExceptionTracker.LogException(e);
             return(string.Empty);
         }
     }
 }
示例#5
0
        public long?GetLastUpdate([FromBody] SimpleRequestInput getLastUpdateAction)
        {
            if (string.IsNullOrEmpty(getLastUpdateAction.Email) ||
                string.IsNullOrEmpty(getLastUpdateAction.AuthToken))
            {
                return(null);
            }
            // Use the email and authToken to get the userId
            string userId = UserController.GetUserId(getLastUpdateAction.Email, getLastUpdateAction.AuthToken);

            if (string.IsNullOrEmpty(userId))
            {
                // Expired AuthToken
                return(null);
            }
            DateTime?lastUpdate = LastUpdateModel.GetLastUpdate(userId);

            if (lastUpdate == null)
            {
                return(null);
            }
            return(lastUpdate.Value.Ticks);
        }
示例#6
0
        public CreateUserResponse CreateUser([FromBody] CreateUserRequest userRequest)
        {
            CreateUserResponse response = new CreateUserResponse();

            if (string.IsNullOrEmpty(userRequest.Email))
            {
                response.Error = "Invalid Input";
                return(response);
            }
            using (RequestTracker request = new RequestTracker(Constant.RequestAPI.CreateUser.ToString(), userRequest.Email))
            {
                try
                {
                    if (userRequest == null)
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        response.Error   = "Invalid Input";
                        return(response);
                    }
                    if (string.IsNullOrEmpty(userRequest.Password) || userRequest.Password.Length < 8)
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        response.Error   = "Password must be at least 8 characters";
                        return(response);
                    }
                    if (string.IsNullOrEmpty(userRequest.Email) || !userRequest.Email.Contains("@") || !userRequest.Email.Contains("."))
                    {
                        request.response = RequestTracker.RequestResponse.UserError;
                        response.Error   = "Invalid email address";
                        return(response);
                    }
                    UserModel retrievedUser;
                    if (UserModel.GetUser(userRequest.Email, out retrievedUser))
                    {
                        if (!retrievedUser.AuthCheck(userRequest.Password))
                        {
                            // User exists and pw is wrong
                            request.response = RequestTracker.RequestResponse.UserError;
                            response.Error   = "User already exists";
                            return(response);
                        }
                        else
                        {
                            // Just let user login
                            // Generate temporary auth token
                            string loginToken = retrievedUser.GetAuthToken();
                            // Store with updated auth table
                            UserModel.UpdateUser(retrievedUser);
                            request.response = RequestTracker.RequestResponse.LoginOnSignup;

                            response.Token = loginToken;
                            response.Error = "Success";
                            return(response);
                        }
                    }

                    UserModel user = new UserModel(userRequest.Email, userRequest.Password);
                    LastUpdateModel.SetLastUpdate(user.UserId);

                    // Generate temporary auth token
                    string token = user.GetAuthToken();
                    user.Save();

                    // Create the tutorial notes
                    foreach (string note in Constant.TutorialNotes)
                    {
                        NoteModel.AddNote(note, string.Empty, 0F, 0F, user.Email, user.UserId);
                    }

                    response.Token = token;
                    response.Error = "Success";
                    return(response);
                }
                catch (Exception e)
                {
                    request.response = RequestTracker.RequestResponse.ServerError;
                    ExceptionTracker.LogException(e);
                    response.Error = "Server Error";
                    return(response);
                }
            }
        }
        private void MergeNewValuesWithOriginal(LastUpdateModel modelFromView)
        {
            //***************************The values that are display only will not be posted back so need to get them from session**************************

            LastUpdateModel OriginalValuesFromSession = SessionManager.CurrentLastUpdate;
        }