示例#1
0
 public bool CheckRight(TaskList taskList, string username, string right)
 {
     var user = db.Users.FirstOrDefault(x => x.UserName == username);
     if (user == null)
     {
         throw new Exception("User does not exist");
     }
     if (taskList.CreatorId == user.Id)
     {
         return true;
     }
     return db.MemberRights.Count(x => x.TaskListId == taskList.Id && x.MemberId == user.Id && x.Right == right) > 0;
 }
示例#2
0
 public void AcceptInvitation(TaskList taskList, string username)
 {
     var user = db.Users.FirstOrDefault(x => x.UserName == username);
     if (user == null)
     {
         throw new Exception("User does not exist");
     }
     if (!taskList.Invited.Contains(user))
     {
         throw new Exception("User is not invited");
     }
     taskList.Invited.Remove(user);
     taskList.Members.Add(user);
     Update(taskList);
 }
示例#3
0
 public void AddRight(TaskList taskList, string username, string right)
 {
     var user = db.Users.FirstOrDefault(x => x.UserName == username);
     if (user == null)
     {
         throw new Exception("User does not exist");
     }
     if (taskList.Members.Count(x => x.Id == user.Id) == 0)
     {
         throw new Exception("User is not a member");
     }
     if (user.Rights.Count(x => x.Right == right && x.TaskListId == taskList.Id) > 0)
     {
         throw new Exception("User already has this right");
     }
     MemberRight dbRight = new MemberRight
     {
         MemberId = user.Id,
         Right = right,
         TaskListId = taskList.Id
     };
     db.MemberRights.Add(dbRight);
     db.SaveChanges();
 }
示例#4
0
 public void Add(TaskList item)
 {
     db.TaskLists.Add(item);
     db.SaveChanges();
 }
示例#5
0
 public void Update(TaskList item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
 }
示例#6
0
 public void RemoveRight(TaskList taskList, string username, string right)
 {
     var user = db.Users.FirstOrDefault(x => x.UserName == username);
     if (user == null)
     {
         throw new Exception("User does not exist");
     }
     if (taskList.Members.Count(x => x.Id == user.Id) == 0)
     {
         throw new Exception("User is not a member");
     }
     if (user.Rights.Count(x => x.Right == right && x.TaskListId == taskList.Id) == 0)
     {
         throw new Exception("User does not have this right");
     }
     var dbRight = db.MemberRights.FirstOrDefault(x => x.TaskListId == taskList.Id && x.MemberId == user.Id && x.Right == right);
     db.MemberRights.Remove(dbRight);
     db.SaveChanges();
 }
示例#7
0
 public void Invite(TaskList taskList, string username)
 {
     var user = db.Users.FirstOrDefault(x => x.UserName == username);
     if (user == null)
     {
         throw new Exception("User does not exist");
     }
     if (taskList.Invited.Contains(user))
     {
         throw new Exception("User already invited");
     }
     if (taskList.Members.Contains(user))
     {
         throw new Exception("User is already member");
     }
     if (taskList.Creator.Id == user.Id)
     {
         throw new Exception("User is creator");
     }
     taskList.Invited.Add(user);
     Update(taskList);
 }
示例#8
0
 public void Delete(TaskList item)
 {
     db.TaskLists.Remove(item);
     db.SaveChanges();
 }
示例#9
0
        public IHttpActionResult Create([FromBody]CreateRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var taskList = new TaskList
            {
                CreatorId = CurrentUser.Id,
                Description = model.Description,
                Name = model.Name,
                Type = model.Type == "team" ? TaskListType.Team : TaskListType.Personal
            };

            taskListService.Add(taskList);

            return Created(Request.RequestUri, Mapper.Map<BaseTaskListResponseModel>(taskList));
        }