예제 #1
0
        public ActionResult <Notes> DeleteNotes([FromBody] NotesRequest notesRequest)
        {
            Notes notes = dbContext.Notes.Where(n => n.Id == notesRequest.id).SingleOrDefault();

            dbContext.Notes.Remove(notes);
            dbContext.SaveChanges();
            return(notes);
        }
예제 #2
0
        public ActionResult <Notes> UpdateNotes([FromBody] NotesRequest notesRequest)
        {
            Notes notes = dbContext.Notes.Where(n => n.PageId == notesRequest.pageid && n.Id == notesRequest.id).SingleOrDefault();

            notes.Name       = notesRequest.name;
            notes.Title      = notesRequest.title;
            notes.ModifiedOn = DateTime.Now;
            dbContext.SaveChanges();
            return(notes);
        }
예제 #3
0
 public string UpdateNote(Guid id, [FromBody] NotesRequest request, Guid userid)
 {
     if (UserSession.GetUserSession(userid) == true)
     {
         var noteService = new NoteService();
         noteService.UpdateNote(id, request);
         return("Note Updated");
     }
     throw new Exception("Please Login first");
 }
예제 #4
0
 public string CreateNote([FromBody] NotesRequest request, Guid userid)
 {
     if (UserSession.GetUserSession(userid) == true)
     {
         var noteService = new NoteService();
         noteService.InsertNote(request, userid);
         return("Note Created");
     }
     throw new Exception("Please Login first");
 }
예제 #5
0
 public IEnumerable <Note> Post([FromBody] NotesRequest request)
 {
     return(_notesManager.ListNotes()
            .Where(note => request.ContentPart == null ||
                   note.Content.Contains(request.ContentPart))
            .FilterBy(request.Id, note => note.Id)
            .AddCreatorNames(_creatorsManager)
            .Where(note => request.NamePart == null ||
                   note.CreatorName.Contains(request.NamePart))
            .OrderBy(request.OrderBy, noteFieldsMap));
 }
예제 #6
0
        public ActionResult <Notes> CreateNotes([FromBody] NotesRequest notesRequest)
        {
            Notes notes = new Notes();

            notes.PageId     = notesRequest.pageid;
            notes.Name       = notesRequest.name;
            notes.CreatedOn  = DateTime.Now;
            notes.ModifiedOn = DateTime.Now;
            dbContext.Notes.Add(notes);
            dbContext.SaveChanges();
            return(notes);
        }
예제 #7
0
        public string UpdateNote(Guid id, NotesRequest request)
        {
            var notes = new Notes
            {
                Title   = request.Title,
                Content = request.Content,
                Id      = id
            };
            var dbManager = DbFactory.GetInstance("mongo");

            dbManager.UpdateNote(id, notes);
            return("Note updated successfully.");
        }
예제 #8
0
 public override Task <NotesResponse> Query(NotesRequest request, ServerCallContext context)
 {
     if (request.Key == Note.C)
     {
         return(Task.FromResult(new NotesResponse
         {
             Name = request.Name,
             Key = request.Key,
             Notes =
             {
                 Note.C, Note.E, Note.G
             }
         }));
     }
     return(base.Query(request, context));
 }
예제 #9
0
        public string InsertNote(NotesRequest request, Guid userId)
        {
            var notes = new Notes {
                Id          = Guid.NewGuid(),
                UserId      = userId,
                Title       = request.Title,
                Content     = request.Content,
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now
            };

            var dbManager = DbFactory.GetInstance("mongo");

            dbManager.InsertNote(notes);
            return("Note inserted successfully.");
        }
예제 #10
0
        static void Main(string[] args)
        {
            var channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);

            var client = new MusicService.MusicServiceClient(channel);

            var request = new NotesRequest
            {
                Key  = Note.C,
                Name = "Major"
            };

            var response = client.Query(request);

            foreach (var note in response.Notes)
            {
                Console.WriteLine(note);
            }

            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
예제 #11
0
        public static void Main(string[] args)
        {
            bool                    showHelp        = false;
            bool                    listCreators    = false;
            bool                    listNotes       = false;
            bool                    compareCreators = false;
            bool                    addNote         = false;
            bool                    updateNote      = false;
            bool                    deleteNote      = false;
            int                     firstCreator    = 0;
            int                     secondCreator   = 0;
            string                  orderBy         = null;
            FilterOption <int>      id             = null;
            string                  namePart       = null;
            string                  notePart       = null;
            FilterOption <int>      numberOfSeries = null;
            FilterOption <int>      numberOfComics = null;
            FilterOption <DateTime> modifiedDate   = null;
            string                  host           = "http://localhost:50296/";
            string                  noteText       = null;
            int                     noteId         = 0;

            var p = new OptionSet()
            {
                "Usage: ",
                "Example:  -L -c=5 -i=\">4000\" -o=-note,comics,name,-date,-id -N" +
                " -C -a=8764 -b=8571 -A -d=11122 -x=\"New Note!!!\" -U -D",
                "Options:",
                { "h|Help", "Show this message and exit.",
                  h => showHelp = h != null },
                { "H|Host=", "Set remote host address. Example: \n" +
                  " -H=\"http://ec2-52-15-204-100.us-east-2.compute.amazonaws.com\"",
                  H => { if (H != null)
                         {
                             host = H;
                         }
                  } },
                { "L|List", "List Creators.",
                  L => listCreators = L != null },
                { "N|Notes", "List Notes.",
                  N => listNotes = N != null },
                { "o|order=", "Order by string, possible any coma " +
                  "separated combination of values and '-' for descending. \n" +
                  "Values for Creators: id, name, date, comics, series, note. \n" +
                  "Values for Notes: id, name, note. \n" +
                  "E.g.: -o=-note,comics,name,-date,-id",
                  o => orderBy = o },
                { "i|id=", "Filter by id.",
                  i => { id = SetFilter(i, int.Parse); } },
                { "n|name=", "Filter by name.",
                  n => namePart = n },
                { "t|note=", "Filter by note.",
                  t => notePart = t },
                { "s|series=", "Filter by series.",
                  s => { numberOfSeries = SetFilter(s, int.Parse); } },
                { "c|comics=", "Filter by comics.",
                  c => { numberOfComics = SetFilter(c, int.Parse); } },
                { "m|modified=", "Filter by modified date, e.g.: -m=\">2007-01-02\"",
                  m => { modifiedDate = SetFilter(m, DateTime.Parse); } },
                { "C|Compare", "Compare Creators.",
                  C => compareCreators = C != null },
                { "a|first=", "First Creator Id.",
                  (int a) => firstCreator = a },
                { "b|second=", "Second Creator Id.",
                  (int b) => secondCreator = b },
                { "A|Add", "Add Note.",
                  A => addNote = A != null },
                { "U|Update", "Update Note.",
                  U => updateNote = U != null },
                { "D|Delete", "Delete Note.",
                  D => deleteNote = D != null },
                { "d|iD=", "Id for notes operations.",
                  (int d) => noteId = d },
                { "x|text=", "Text for notes operations.",
                  x => noteText = x },
            };

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `--Help' for more information.");
                return;
            }
            if (showHelp)
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            client = new RestClient
            {
                BaseUrl = new Uri(host),
                Timeout = 30000,
            };

            if (listCreators)
            {
                var request = new CreatorsRequest()
                {
                    Id             = id,
                    ModifiedDate   = modifiedDate,
                    NamePart       = namePart,
                    NotePart       = notePart,
                    NumberOfComics = numberOfComics,
                    NumberOfSeries = numberOfSeries,
                    OrderBy        = ParseOrder(orderBy),
                };
                ExecuteRequest <List <Creator> >(
                    "api/Creators", Method.POST, request,
                    responseList => responseList.Any());
            }

            if (listNotes)
            {
                var request = new NotesRequest()
                {
                    Id          = id,
                    NamePart    = namePart,
                    ContentPart = notePart,
                    OrderBy     = ParseOrder(orderBy),
                };
                ExecuteRequest <List <Note> >(
                    "api/Notes", Method.POST, request,
                    responseList => responseList.Any());
            }

            if (compareCreators)
            {
                var request = new CreatorsComparisonRequest()
                {
                    FirstId  = firstCreator,
                    SecondId = secondCreator,
                };
                ExecuteRequest <CreatorsComparison>(
                    "api/CreatorsComparison", Method.POST, request, response =>
                    response.ComparisonStatus == CreatorsComparisonStatus.ComparisonSuccessful);
            }

            if (addNote)
            {
                var request = new NoteOperationRequest()
                {
                    Id      = noteId,
                    Content = noteText,
                };
                ExecuteRequest <NoteOperationResponse>(
                    "api/NoteOperations", Method.POST, request, response => false);
            }

            if (updateNote)
            {
                var request = new NoteOperationRequest()
                {
                    Id      = noteId,
                    Content = noteText,
                };
                ExecuteRequest <NoteOperationResponse>(
                    "api/NoteOperations", Method.PUT, request, response => false);
            }

            if (deleteNote)
            {
                var request = new NoteOperationRequest()
                {
                    Id = noteId,
                };
                ExecuteRequest <NoteOperationResponse>(
                    "api/NoteOperations", Method.DELETE, request, response => false);
            }
        }