public Response CreateShare(CreateShareRequest request)
        {
            try
            {
                CreateShareResponse retval = new CreateShareResponseUserNotExists();

                var userExists = _userDal.GetUser(request.UserId);
                if (userExists.Tables.Count > 0)
                {
                    var tbl = userExists.Tables[0];
                    if (tbl.Rows.Count > 0)
                    {
                        var            ds  = _dal.CreateShare(request.UserId, request.DocId);
                        MessageRequest msg = new MessageRequest(null, request.DocId, "sharingAdded");
                        _wsService.Send(msg);
                        retval = new CreateShareResponseOK();
                    }
                }
                return(retval);
            }
            catch (Exception ex)
            {
                return(new ResponseError(ex.Message));
            }
        }
        public async Task <Response> CreateShare(CreateShareRequest request)
        {
            Response retval;

            if (_dal.IsShareExists(_conn, request.Share))
            {
                retval = new CreateShareResponseShareExists(request);
            }
            else if (!_dal.IsDocumentExists(_conn, request.Share.DocID) || !_dal.IsUserExists(_conn, request.Share.UserID))
            {
                retval = new CreateShareResponseInvalidID(request);
            }
            else if (!_dal.IsUserOwner(_conn, request.UserID, request.Share.DocID))
            {
                retval = new CreateShareResponseNotAuthorized(request);
            }
            else
            {
                try
                {
                    _dal.CreateShare(_conn, request.Share);
                    retval = new CreateShareResponseOK(request);
                    await _webSocket.Notify("New share: " + request.Share.ToString());
                }
                catch (Exception ex)
                {
                    retval = new AppResponseError("Error in create share");
                }
            }

            return(retval);
        }
Example #3
0
        public async Task <Response> CreateShare(CreateShareRequest request)
        {
            Response response = new CreateShareResponseInvalidUserID(request);

            if (_dal.isUserExists(request.Share.UserID) && _dal.isDocExists(request.Share.DocID))
            {
                try
                {
                    //create share
                    DataSet ds = _dal.CreateShare(request.Share.DocID, request.Share.UserID);
                    response = new CreateShareResponseOK(request);
                    //update user for new share
                    await _socket.Send(request.Share.UserID, "newDocumentUpdate");
                }
                catch (Exception ex)
                {
                    response = new AppResponseError(ex.Message);
                }
            }
            return(response);
        }