Beispiel #1
0
        public Notes CreateNotes(string description, string date)
        {
            DateTime dateParsed;

            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentNullException(nameof(description), "Note Description was not provided.");
            }
            else
            {
                description = description.Trim();
            }

            if (string.IsNullOrWhiteSpace(date))
            {
                throw new ArgumentNullException(nameof(date), "Date was not provided.");
            }
            else
            {
                date = date.Trim();
                if (!DateTime.TryParse(date, out dateParsed))
                {
                    throw new ArgumentException("Date is not valid.", nameof(date));
                }
                else
                {
                    if (dateParsed > DateTime.Today)
                    {
                        throw new ArgumentException("Date can not be in Future.", nameof(date));
                    }
                }
            }

            Notes newNote = new Notes()
            {
                Description = description,
                Date        = dateParsed
            };

            using (NoteContext context = new NoteContext())
            {
                context.Notes.Add(newNote);
                context.SaveChanges();
            }

            return(newNote);
        }
        public Notes CreateNotes(string description, string date)
        {
            DateTime dateParsed;

            if (string.IsNullOrWhiteSpace(description)) // Check If Description is Empty and WhiteSpace
            {
                throw new ArgumentNullException(nameof(description), "Notes was not provided.");
            }
            else
            {
                description = description.Trim();
            }
            if (string.IsNullOrWhiteSpace(date)) // Check If Date is Empty and WhiteSpace
            {
                throw new ArgumentNullException(nameof(date), "Date was not provided.");
            }
            else
            {
                date = date.Trim();
                if (!DateTime.TryParse(date, out dateParsed)) // Check If Date is valid or not
                {
                    throw new ArgumentException("Date is not valid.", nameof(date));
                }
            }
            Notes create = new Notes()
            {
                Description = description,
                Date        = dateParsed,
                UserId      = -2
            };

            using (NoteContext context = new NoteContext())
            {
                context.Notes.Add(create);
                context.SaveChanges(); // Save all data to Database
            }
            return(create);
        }
        public Notes EditNotesByID(string id, string description)
        {
            if (string.IsNullOrWhiteSpace(id)) // Check If Description ID is Empty and WhiteSpace
            {
                throw new ArgumentNullException(nameof(id), "Description ID was not provided.");
            }
            else
            {
                id = id.Trim();
            }
            if (string.IsNullOrWhiteSpace(description)) // Check If Description is Empty and WhiteSpace
            {
                throw new ArgumentNullException(nameof(description), "Description was not provided.");
            }
            Notes modified;

            using (NoteContext context = new NoteContext())
            {
                modified             = context.Notes.Where(x => x.ID == int.Parse(id)).Single();
                modified.Description = description;
                context.SaveChanges(); // Save All Changes to Database
            }
            return(modified);
        }