public async Task <IActionResult> AddCollaborators(int NoteId, AddCollaboratorRequest collaborator) { try { if (collaborator.CollaboratorId != 0 && NoteId != 0) { var userId = TokenUserId(); AddCollaboratorResponce data = await note.AddCollaborators(NoteId, userId, collaborator); if (data.CollaborationRecordId != 0) { return(Ok(new { success = true, Meassage = "Add Collabrators SucessessFully", data })); } else { return(BadRequest(new { success = false, Meassage = "Add Collabrators unsuceessful" })); } } else { return(BadRequest(new { success = false, Meassage = "Invalid Credentials" })); } } catch (Exception e) { return(BadRequest(new { success = false, Meassage = e.Message })); } }
public bool addCollaborator(AddCollaboratorRequest addCollaboratorRequest) { try { if (!verifyUser(addCollaboratorRequest.connectionId)) return false; var userId = (from u in _entity.users where u.email == addCollaboratorRequest.userEmail select u).FirstOrDefault(); if (userId == null) return false; _entity.collaborators.Add(new collaborator() { user_id = userId.id, event_id = addCollaboratorRequest.eventId, user_role = addCollaboratorRequest.role }); _entity.SaveChanges(); var connection = (from c in _entity.connections where c.user_id == userId.id select c).FirstOrDefault(); if (connection != null) { var context = GlobalHost.ConnectionManager.GetHubContext<TitanHub>(); context.Clients.Client(connection.connection_id).ReloadEvents(); TitanSync.NotifyClient(connection.connection_id, userId.name + " has been added as a collaborator!", ""); } return true; } catch (Exception) { return false; } }
public async Task <AddCollaboratorResponce> AddCollaborators(int NoteId, int userId, AddCollaboratorRequest collaborator) { try { SqlConnection connection = DBConnection(); SqlCommand command = StoreProcedureConnection("spAddValidCollaborator", connection); command.Parameters.AddWithValue("@UserId", userId); command.Parameters.AddWithValue("@CollaboratorWithId", collaborator.CollaboratorId); command.Parameters.AddWithValue("@NoteId", NoteId); command.Parameters.AddWithValue("@CreatedDateTime", DateTime.Now); connection.Open(); SqlDataReader dataReader = await command.ExecuteReaderAsync(); AddCollaboratorResponce collaboratorResponce = new AddCollaboratorResponce(); if (dataReader.Read()) { collaboratorResponce.CollaborationRecordId = (int)dataReader["CollabratorId"]; collaboratorResponce.UserId = (int)dataReader["UserId"]; collaboratorResponce.CollaboratorId = (int)dataReader["CollabratorWithId"]; collaboratorResponce.NoteId = (int)dataReader["NoteId"]; collaboratorResponce.CreatedDateTime = (DateTime)dataReader["CreatedDateTime"]; } connection.Close(); return(collaboratorResponce); } catch (Exception e) { throw e; } }
/// <summary> /// Adds the collaborators. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="collaborator">The collaborator.</param> /// <returns></returns> public async Task <AddCollaboratorResponce> AddCollaborators(int NoteId, int userId, AddCollaboratorRequest collaborator) { try { return(await notes.AddCollaborators(NoteId, userId, collaborator)); } catch (Exception e) { throw e; } }