Пример #1
0
        public bool DeleteTaskItem(int id, string authorizedUserID)
        {
            using (var db = new NoteeContext())
            {
                var taskItem = db.TaskItems.SingleOrDefault(ti => ti.TaskItemID == id);
                var note = db.Notes.SingleOrDefault(n => n.NoteID == taskItem.NoteID);
                var user = db.SubUsers.SingleOrDefault(u => u.UserID == note.UserID);

                if (authorizedUserID != user.UserID)
                {
                    return false;
                }

                if (taskItem == null)
                {
                    return false;
                }
                else
                {
                    db.TaskItems.Remove(taskItem);
                    db.SaveChanges();
                    new NotesManager().UpdateModificationTime(taskItem.NoteID);
                    return true;
                }
            }
        }
Пример #2
0
        public bool AddOrUpdateTaskItem(TaskItemDTO taskItem, string authorizedUserID)
        {
            using (var db = new NoteeContext())
            {
                var note = db.Notes.SingleOrDefault(n => n.NoteID == taskItem.NoteID);
                var user = db.SubUsers.SingleOrDefault(u => u.UserID == note.UserID);
                if (db.Notes.Any(n => n.NoteID == taskItem.NoteID) && user.UserID == authorizedUserID)
                {
                    TaskItem model;
                    if (taskItem.TaskItemID > 0)
                    {
                        model = db.TaskItems.Single(ti => ti.TaskItemID == taskItem.TaskItemID);
                    }
                    else
                    {
                        model = db.TaskItems.Create();
                        model.Note = db.Notes.Single(n => n.NoteID == taskItem.NoteID);
                        db.TaskItems.Add(model);
                    }

                    model.Text = taskItem.Text;
                    model.IsDone = taskItem.IsDone;

                    db.SaveChanges();
                    taskItem.TaskItemID = model.TaskItemID;
                    new NotesManager().UpdateModificationTime(model.NoteID);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Пример #3
0
        public void AddOrUpdateTaskItems(int noteId, IEnumerable<TaskItemDTO> tasks)
        {
            using (var db = new NoteeContext())
            {

                foreach (var taskItem in tasks)
                {
                    TaskItem model;
                    if (taskItem.TaskItemID > 0)
                    {
                        model = db.TaskItems.Single(ti => ti.TaskItemID == taskItem.TaskItemID);
                    }
                    else
                    {
                        model = db.TaskItems.Create();
                        model.Note = db.Notes.Single(n => n.NoteID == noteId);
                        db.TaskItems.Add(model);
                    }

                    model.Text = taskItem.Text;
                    model.IsDone = taskItem.IsDone;

                    db.SaveChanges();
                    taskItem.TaskItemID = model.TaskItemID;
                    new NotesManager().UpdateModificationTime(model.NoteID);
                }
            }
        }
Пример #4
0
 public UserDTO GetUser(string id)
 {
     using (var db = new NoteeContext())
     {
         var user = db.SubUsers.SingleOrDefault(u => u.UserID == id);
         return user == null ? null : new UserDTO(user);
     }
 }
Пример #5
0
        public bool AddOrUpdateNote(NoteDTO note, string authorizedUserID)
        {
            using (var db = new NoteeContext())
            {
                var user = db.SubUsers.SingleOrDefault(u => u.UserID == note.UserID);
                if (user.UserID != authorizedUserID)
                {
                    return false;
                }
                Note model;
                if (db.SubUsers.Any(u => u.UserID == note.UserID))
                {
                    if (note.NoteID > 0)
                    {
                        model = db.Notes.Single(n => n.NoteID == note.NoteID);
                    }
                    else
                    {
                        model = db.Notes.Create();
                        model.User = db.SubUsers.Single(u => u.UserID == note.UserID);
                        db.Notes.Add(model);
                    }

                    model.Title = note.Title;
                    model.Text = note.Text;
                    model.NoteType = note.Type;
                    model.ModificationDate = DateTime.Now;
                    model.Color = note.Color;
                    model.ImageUrl = note.ImageUrl;
                    model.Label = note.Label;
                    model.isLocked = note.IsLocked;

                    db.SaveChanges();
                    note.NoteID = model.NoteID;
                    note.ModificationDate = model.ModificationDate;

                }
                else
                {
                    return false;
                }
                new TaskItemsManager().AddOrUpdateTaskItems(model.NoteID, note.TaskItems);
                note.TaskItems.Clear();
                model.TaskItems.ToList().ForEach(ti => note.TaskItems.Add(new TaskItemDTO(ti)));
            }
            return true;
        }
Пример #6
0
        public void AddOrUpdateUser(UserDTO user)
        {
            using (var db = new NoteeContext())
            {
                var model = db.SubUsers.SingleOrDefault(u => u.UserID == user.UserID);
                if(model == null)
                {
                    model = db.SubUsers.Create();
                    model.UserID = user.UserID;
                    db.SubUsers.Add(model);
                }

                db.SaveChanges();
                user.UserID = model.UserID;

                new NotesManager().AddOrUpdateNotes(model.UserID, user.Notes);
                user.Notes.Clear();
                model.Notes.ToList().ForEach(n => user.Notes.Add(new NoteDTO(n)));
            }
        }
Пример #7
0
        public void AddOrUpdateNotes(string userId, IEnumerable<NoteDTO> notes)
        {
            foreach (var note in notes)
            {
                using (var db = new NoteeContext())
                {
                    Note model;
                    if (note.NoteID > 0)
                    {
                        model = db.Notes.Single(n => n.NoteID == note.NoteID);
                    }
                    else
                    {
                        model = db.Notes.Create();
                        model.User = db.SubUsers.Single(u => u.UserID == userId);
                        db.Notes.Add(model);
                    }

                    model.Title = note.Title;
                    model.Text = note.Text;
                    model.NoteType = note.Type;
                    model.ModificationDate = DateTime.Now;
                    model.Color = note.Color;
                    model.ImageUrl = note.ImageUrl;
                    model.Label = note.Label;
                    model.isLocked = note.IsLocked;

                    db.SaveChanges();
                    note.NoteID = model.NoteID;
                    note.ModificationDate = model.ModificationDate;
                    new TaskItemsManager().AddOrUpdateTaskItems(model.NoteID, note.TaskItems);
                    note.TaskItems.Clear();
                    model.TaskItems.ToList().ForEach(ti => note.TaskItems.Add(new TaskItemDTO(ti)));
                }
            }
        }
Пример #8
0
 public bool DeleteNote(int id, string authorizedUserID)
 {
     using (var db = new NoteeContext())
     {
         var note = db.Notes.SingleOrDefault(n => n.NoteID == id);
         var user = db.SubUsers.SingleOrDefault(u => u.UserID == note.UserID);
         if (user.UserID != authorizedUserID)
         {
             return false;
         }
         if (note != null)
         {
             db.Notes.Remove(note);
             db.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Пример #9
0
 public bool UpdateModificationTime(int id)
 {
     using (var db = new NoteeContext())
     {
         var note = db.Notes.SingleOrDefault(n => n.NoteID == id);
         if (note != null)
         {
             note.ModificationDate = DateTime.Now;
             db.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Пример #10
0
 public NoteDTO GetNote(int id, string authorizedUserID)
 {
     using (var db = new NoteeContext())
     {
         var note = db.Notes.SingleOrDefault(n => n.NoteID == id);
         var user = db.SubUsers.SingleOrDefault(u => u.UserID == note.UserID);
         if (user.UserID != authorizedUserID)
         {
             return null;
         }
         return note == null ? null : new NoteDTO(note);
     }
 }