public Response GetAllMarkers(string documentId) { Response response = new GetMarkersResponseOk(); try { var results = _drawingDal.GetAllMarkers(documentId); var markers = results.Tables[0].AsEnumerable() .Select(row => new Marker { Color = row.Field <string>("COLOR"), DocId = documentId, OwnerUser = row.Field <string>("OWNER_USER_ID"), MarkerId = row.Field <string>("MARKER_ID"), Position = row.Field <string>("POS"), MarkerType = TryParseMarker((string)row["MARK_TYPE"]) }); ((GetMarkersResponseOk)response).Markers = markers; } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public async Task <Response> CreateDocument(CreateDocumentRequest request) { Response retval = new CreateDocumentResponseInvalidData(request); if (_dal.IsUserExists(_conn, request.UserID)) { var id = Guid.NewGuid().ToString(); Document document = new Document() { DocID = id, DocumentName = request.DocumentName, ImageURL = request.ImageURL, UserID = request.UserID }; try { _dal.CreateDocument(_conn, document); retval = new CreateDocumentResponseOK(request); await _webSocket.Notify("new Document" + id); } catch (Exception ex) { retval = new AppResponseError("Error in create document"); } } return(retval); }
public async Task <Response> RemoveShare(RemoveShareRequest request) { Response retval = new RemoveShareResponseInvalidID(request); if (!_dal.IsShareExists(_conn, request.Share)) { retval = new RemoveShareResponseInvalidID(request); } else if (request.UserID != request.Share.UserID && !_dal.IsUserOwner(_conn, request.UserID, request.Share.DocID)) { retval = new RemoveShareResponseNotAuthorized(request); } else { try { _dal.removeShare(_conn, request.Share); retval = new RemoveShareResponseOK(request); await _webSocket.Notify("remove share: " + request.Share.ToString()); } catch { retval = new AppResponseError("Error in server in remove share"); } } return(retval); }
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); }
public async Task <Response> GetUsers(GetUsersRequest request) { Response response = new GetUsersResponseInvalid(request); if (_dal.isUserExists(request.User.UserID)) { try { List <User> users = new List <User>(); DataSet db = _dal.GetUsers(); foreach (DataRow row in db.Tables[0].Rows) { var user = new User(); user.UserID = (string)row["USER_ID"]; user.UserName = (string)row["USER_NAME"]; users.Add(user); } response = new GetUsersResponseOK(users); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public Response GetAllUsersForSharing(GetAllUsersForSharingRequest request) { Response response = new GetAllUsersForSharingResponseOk(); try { var results = _drawingDal.GetAllUsers(); IEnumerable <SharingUserInfo> allUsers = results.Tables[0].AsEnumerable() .Select(ConvertRowToUserObject).Where(obj => obj.IsActive); if (allUsers.Any()) { var dbUsers = _drawingDal.GetSharedUserByDocumentId(request.DocId); var sharedUsers = dbUsers.Tables[0].AsEnumerable() .Select(ConvertRowToUserObject).Where(obj => obj.IsActive); allUsers = MarkUserAsShared(allUsers, sharedUsers); } ((GetAllUsersForSharingResponseOk)response).Users = allUsers; } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response DeleteDocumentById(DeleteDocumentRequest request) { Response response = new DeleteDocumentResponseOk(request); try { var document = _drawingDal.GetDocumentById(request.DocId); if (document.Tables[0].Rows.Count == 1) { var fileName = ConvertRowToDocumentObject(document.Tables[0].Rows[0]).DocUrl; _drawingDal.DeleteDocument(request); TryDeletingFile(fileName); } else { response = new DeleteDocumentInvalidIdResponse(); } } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response GetDocumentById(string id) { Response response; try { var document = _drawingDal.GetDocumentById(id); if (document.Tables[0].Rows.Count == 1) { var row = document.Tables[0].Rows[0]; response = new GetDocumentResponseOk(ConvertRowToDocumentObject(row)); ((GetDocumentResponseOk)response).Image = GetFileBytes(((GetDocumentResponseOk)response).Doc.DocUrl); } else { response = new GetDocumentResponseInvalidId(); } } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public async Task <Response> UploadPhoto([FromForm(Name = "File")] IFormFile File) { Response response = new FileUploadResponseError(File); var file = File; Console.WriteLine(file); var uploadResult = new ImageUploadResult(); try { if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams { File = new FileDescription(file.FileName, stream), }; uploadResult = _cloudinary.Upload(uploadParams); } } response = new FileUploadResponseOK(uploadResult.Url.ToString()); } catch (Exception ex) { response = new AppResponseError(ex.Message); } return(response); }
public Response ShareDocument(ShareDocumentRequest request) { Response response = new ShareDocumentResponseOk(request); try { var user = _drawingDal.GetUser(new SignInRequest { LoginDto = new LoginDto { Email = request.UserId } }); if (user.Tables[0].Rows.Count > 0) { _drawingDal.ShareDocument(request); } else { response = new ShareDocumentNoUserFoundResponse(request); } } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public async Task <Response> GetDocument(GetDocumentRequest request) { Response retval = new GetDocumentResponseInvalidDocID(request); if (_dal.IsDocumentExists(_conn, request.DocId)) { try { DataSet ds = _dal.GetDocument(_conn, request.DocId); var data = ds.Tables[0].Rows[0]; Document doc = new Document() { DocID = (string)data["document_id"], DocumentName = (string)data["document_name"], ImageURL = (string)data["image_url"], UserID = (string)data["user_id"] }; retval = new GetDocumentResponseOK(doc); } catch { retval = new AppResponseError("Error in get document"); } } return(retval); }
public async Task <Response> GetDocuments(GetDocumentsRequest request) { Response response = new GetDocumentsResponseInvalidUserID(request); if (_dal.isUserExists(request.UserID)) { try { DataSet ds = _dal.GetDocuments(request.UserID); List <Document> docs = new List <Document>(); foreach (DataRow row in ds.Tables[0].Rows) { var doc = new Document(); doc.DocID = (string)row["DOC_ID"]; doc.UserID = (string)row["USER_ID"]; doc.DocumentName = (string)row["DOCUMENT_NAME"]; doc.ImageURL = (string)row["IMAGE_URL"]; docs.Add(doc); } response = new GetDocumentsResponseOK(docs); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public async Task <Response> GetDocument(GetDocumentRequest request) { Response response = new GetDocumentResponseInvalidDocID(request); if (_dal.isDocExists(request.DocID)) { try { DataSet ds = _dal.GetDocument(request.DocID); var docData = ds.Tables[0].Rows[0]; var doc = new Document(); doc.DocID = (string)docData["DOC_ID"]; doc.UserID = (string)docData["USER_ID"]; doc.DocumentName = (string)docData["DOCUMENT_NAME"]; doc.ImageURL = (string)docData["IMAGE_URL"]; response = new GetDocumentResponseOK(doc); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public async Task <Response> GetMarkers(GetMarkersRequest request) { //TODO test Response retval = new GetMarkersResponseInvalidDocID(request); if (_dal.IsDocumentExists(_conn, request.DocID)) { try { List <Marker> markers = new List <Marker>(); DataSet ds = _dal.GetMarkers(_conn, request.DocID); foreach (DataRow row in ds.Tables[0].Rows) { markers.Add(CreateMarkerFromRow(row)); } retval = new GetMarkersResponseOk(markers); } catch (Exception ex) { retval = new AppResponseError("Error in get markers"); } } return(retval); }
public Response removeDoc(string docId) { Response retval = null; try { if (_dal.GetDoc(docId).Tables[0].Rows.Count == 1) // doc exsist { _dal.RemoveDoc(docId); //check removing var docRow = _dal.GetDoc(docId).Tables[0].Rows; if (docRow.Count == 0) // success - the doc isn't found { retval = new RemoveDocResponseOk("Document removed successfuly!"); } else { retval = new RemoveDocResponseError("Removing failed!"); } } else { retval = new RemoveDocResponseError("This document doesn't exist!"); } } catch (Exception ex) { retval = new AppResponseError(ex.Message); } return(retval); }
public async Task <Response> GetMarker(GetMarkerRequest request) { Response response = new GetMarkerResponseInvalid(request); try { Marker marker = new Marker(); DataSet ds = _dal.GetMarker(request.MarkerID); var markerData = ds.Tables[0].Rows[0]; marker.DocID = (string)markerData["DOC_ID"]; marker.MarkerID = (string)markerData["MARKER_ID"]; marker.UserID = (string)markerData["USER_ID"]; marker.MarkerType = (string)markerData["MARKER_TYPE"]; marker.StrokeColor = (string)markerData["STROKE_COLOR"]; marker.BackgroundColor = (string)markerData["BACKGROUND_COLOR"]; marker.X = (string)markerData["X"]; marker.Y = (string)markerData["Y"]; marker.XRadius = (string)markerData["XRADIUS"]; marker.YRadius = (string)markerData["YRADIUS"]; response = new GetMarkerResponseOK(marker); } catch (Exception ex) { response = new AppResponseError(ex.Message); } return(response); }
public Response DeleteMarker(DeleteMarkerRequest request) { Response response = new DeleteMarkerResponseOk(request); try { _drawingDal.DeleteMarker(request.MarkerId); } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response EditMarkerById(EditMarkerRequest request) { Response response = new EditMarkerResponseOk(request); try { _drawingDal.EditMarkerById(request); } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response CreateShare(ShareRequest request) { Response retval; try { var dsShare = _dal.CreateShare(request); retval = new ResponseOk <string>("Share was Created!"); } catch (Exception ex) { retval = new AppResponseError("Sharing not created\n" + ex.Message); } return(retval); }
public Response removeShare(ShareRequest request) { Response retval; try { var dsShare = _dal.RemoveShare(request); retval = new ResponseOk <string>("Remove share for this user"); } catch (Exception ex) { retval = new AppResponseError("Can't remove now\n" + ex.Message); } return(retval); }
public Response UploadDocument(string documentName, string filePath, string userId) { Response response = new UploadDocumentResponseOk(); var docId = Guid.NewGuid().ToString(); try { _drawingDal.UploadDocument(docId, userId, filePath, documentName); } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response CreateMarker(CreateMarkerRequest request) { Response response = new CreateMarkerResponseOk(request); var markerId = Guid.NewGuid().ToString(); request.Marker.MarkerId = markerId; try { _drawingDal.CreateMarker(request); } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public Response CreateMarker(CreateMarkerRequest request) { Response retval = new AppResponseError("Can't create marker\n"); try { var dsMarker = _dal.CreateMarker(request); if (dsMarker.Tables[0].Rows.Count == 1) { retval = new CreateMarkerResponseOk("Marker Created"); } } catch (Exception ex) { retval = new CreateMarkerResponseErr("Can't create marker\n" + ex.Message); } return(retval); }
public async Task <Response> RemoveDocument(RemoveDocumentRequest request) { Response response = new RemoveDocumentResponseInvalidDocID(request); if (_dal.isDocExists(request.DocID)) { try { _dal.RemoveDocument(request.DocID); response = new RemoveDocumentResponseOK(request); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public Response RemoveUser(string userId) { Response retval = new RemoveUserResponseError("Removing faild");; try { var data = _dal.RemoveUser(userId); // mark as remove, return refCursor if (data != null) { retval = new RemoveUserResponseOk("Removed successfuly"); } } catch (Exception ex) { retval = new AppResponseError(ex.Message); } return(retval); }
public Response GetSharedDocument(GetSharedDocumentsRequest request) { Response response = new GetSharedDocumentsResponseOk(request); try { var results = _drawingDal.GetSharedDocument(request.UserId); var allDocuments = results.Tables[0].AsEnumerable() .Select(ConvertRowToDocumentObject); ((GetSharedDocumentsResponseOk)response).Documents = allDocuments; } catch (Exception e) { response = new AppResponseError(e.Message); } return(response); }
public async Task <Response> RemoveMarker(RemoveMarkerRequest request) { Response response = new RemoveMarkerResponseInvalidMarkerID(request); if (_dal.isMarkerExists(request.MarkerID)) { try { _dal.RemoveMarker(request.MarkerID); response = new RemoveMarkerResponseOK(request); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public async Task <Response> RemoveUser(RemoveUserRequest request) { Response retval = new RemoveUserResponseUserIDNotExists(request); if (_dal.IsUserExists(_conn, request.User.UserID)) { try { _dal.RemoveUser(_conn, request.User.UserID); retval = new RemoveUserResponseOK(request); } catch { retval = new AppResponseError("Couldn't remove user, due to error in dataBase"); } } return(retval); }
public async Task <Response> UnSubscribe(UnSubscribeRequest request) { Response response = new UnSubscribeResponseInvalidUserID(request); if (_dal.isUserExists(request.User.UserID)) { try { _dal.UnSubscribe(request.User.UserID, request.User.UserName); response = new UnSubscribeResponseOK(request); } catch (Exception ex) { response = new AppResponseError(ex.Message); } } return(response); }
public Response logout(string userId) { Response retval = new LogoutResponseError("Can't logout now!"); try { var userRow = _dal.Logout(userId).Tables[0].Rows; if (userRow[0].Field <Decimal>("ISLOGIN") == 0) { retval = new LogoutResponseOk("You are Logout!"); } } catch (Exception ex) { retval = new AppResponseError(ex.Message); } return(retval); }