Exemple #1
0
        public override async Task <Reply> Delete(StringId request, ServerCallContext context)
        {
            var reply = new Reply();
            var user  = await _userService.GetUser(context.GetHttpContext());

            if (user == null)
            {
                reply.Error = Error.NeedLogin;
                return(reply);
            }

            if (!user.HasWritePermission())
            {
                reply.Error = Error.NoPermission;
                return(reply);
            }

            if (Guid.TryParse(request.Id, out var id))
            {
                var item = await _service.All().Where(k => k.Id == id).FirstOrDefaultAsync();

                if (item != null)
                {
                    await _service.Delete(item);
                }
                else
                {
                    reply.Error = Error.NoSuchEntity;
                }
            }
            else
            {
                reply.Error = Error.InvalidArguments;
            }

            return(reply);
        }