Esempio n. 1
0
 public JsonResult Delete(Group target)
 {
     if (target.OwnerId != this.User.Id) {
         throw new AuthorizeException("您必須是該群組的擁有者");
     }
     target.Delete(Database);
     return new ApiResult();
 }
Esempio n. 2
0
 public JsonResult Create(
     [FromForm]string name = "未命名群組")
 {
     Group result = new Group() {
         Name = name,
         Owner = User
     };
     Database.Group.Add(result);
     Database.SaveChanges();
     return new ApiResult() {
         Result = result
     };
 }
Esempio n. 3
0
 public JsonResult AddMembers(
     Group target,
     User user)
 {
     if (target.OwnerId != this.User.Id) {
         throw new AuthorizeException("您必須是該群組的擁有者");
     }
     if (target.OwnerId == user.Id ||
         target.IsMember(user, Database)) {
         throw new ApiInvalidOperationException("重複加入的使用者");
     }
     target.AddMember(user, Database);
     return new ApiResult();
 }
Esempio n. 4
0
        public JsonResult GroupShareList(
            Group target,
            [FromQuery]int index = 0,
            [FromQuery]int length = 10,
            [FromQuery]OrderTypes order = OrderTypes.DirFirst) {
            if (target == null) throw new ApiArgumentException($"{nameof(target)}不該為null");
            if (!target.IsMember(User, Database)) throw new AuthorizeException("必須是成員");

            var data = from t in Database.FileNode.Include(x => x.Parent)
                       where
                           t.GroupId == target.Id &&
                           t.Parent.GroupId != target.Id
                       select t;

            if (order == OrderTypes.DirFirst) {
                data = from t in data
                       orderby t.IsFile, t.Ext, t.Name
                       select t;
            } else if (order == OrderTypes.FileFirst) {
                data = from t in data
                       orderby t.IsFile, t.Ext descending, t.Name
                       select t;
            }

            var result = new ApiResult() {
                Result = data.Skip(index).Take(length)
            };
            result.Type.Index = index;
            result.Type.Length = length;
            result.Type.Count = data.Count();

            return result;
        }
Esempio n. 5
0
 public JsonResult Put(
     Group target,
     [FromForm]string name = "未命名群組")
 {
     if (target.OwnerId != User.Id) throw new ApiInvalidOperationException("您必須是該群組的擁有者");
     target.Name = name;
     Database.SaveChanges();
     return new ApiResult();
 }
Esempio n. 6
0
        public JsonResult GetMembers(
            Group target,
            [FromQuery]string keyword = "",
            [FromQuery]int index = 0,
            [FromQuery]int length = 10)
        {
            if (target == null) throw new ApiArgumentException($"{nameof(target)}不該為null");
            if (User.Authority != UserAuthority.Admin && !target.IsMember(User, Database)) {
                throw new AuthorizeException();
            }
            keyword = keyword.Trim();
            var data = target.GetMembers(Database).Where(x => x.Name.Contains(keyword) || x.Id.Contains(keyword));

            data = data.OrderBy(x => x.Name);

            var result = new ApiResult() {
                Result = data.Skip(index).Take(length)
            };

            result.Type.Index = index;
            result.Type.Length = length;
            result.Type.Count = data.Count();
            return result;
        }
Esempio n. 7
0
        public JsonResult GetGroup(Group target)
        {
            if (target == null) throw new ApiArgumentException($"{nameof(target)}不該為null");
            if (User.Authority != UserAuthority.Admin && !target.IsMember(User, Database)) {
                throw new AuthorizeException();
            }

            return new ApiResult() {
                Result = target
            };
        }
Esempio n. 8
0
 public JsonResult Delete(Group target, User user)
 {
     if (target.OwnerId != this.User.Id && !target.IsMember(user, Database)) {
         throw new AuthorizeException("您必須是該群組的擁有者");
     }
     target.RemoveMember(user, Database);
     return new ApiResult();
 }