示例#1
0
        public void Edit(DirectoryEdit data, int userId)
        {
            var directory = this.context.Directories.SingleOrDefault(x => x.Id == data.DirectoryId);

            if (directory == null)
            {
                throw new ServiceException("Directory Not Found!");
            }

            var user = this.context.Users.SingleOrDefault(x => x.Id == userId);

            if (user == null)
            {
                throw new ServiceException("User Not Found!");
            }

            if (user.Id != directory.UserId)
            {
                throw new ServiceException("Directory Does Not Belong To You!");
            }

            //TODO: VALIDATE NAME
            directory.Name = data.NewName;
            context.SaveChanges();
        }
 public IActionResult Edit([FromBody] DirectoryEdit data)
 {
     try
     {
         var userData = jwtService.ParseData(this.User);
         dirService.Edit(data, userData.UserId);
         return(Ok());
     }
     catch (ServiceException e)
     {
         return(BadRequest(e.Message));
     }
 }