Ejemplo n.º 1
0
 /// <summary>
 /// Adds the collaborators to notes.
 /// </summary>
 /// <param name="collaborator">The collaborator.</param>
 /// <returns></returns>
 /// <exception cref="Exception"></exception>
 public CollbratorModel AddCollaboratorToNotes(CollbratorResponse collaborator, long UserId, long NoteId)
 {
     try
     {
         bool result = this.collbratorcontext.Notes.Any(option => option.UserId == UserId && option.NoteId == NoteId);
         if (result)
         {
             Collaborator addCollaborator = new Collaborator()
             {
                 CollaboratorEmail = collaborator.CollaboratorEmail,
             };
             this.collbratorcontext.Collaborators.Add(addCollaborator);
         }
         this.collbratorcontext.SaveChangesAsync();
         var             col         = collbratorcontext.Collaborators.FirstOrDefault(N => N.NoteId == NoteId && N.UserId == UserId);
         CollbratorModel collbrator1 = new CollbratorModel
         {
             CollaboratorId    = col.CollaboratorId,
             CollaboratorEmail = col.CollaboratorEmail,
             NoteId            = NoteId,
             UserId            = UserId,
         };
         return(collbrator1);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Ejemplo n.º 2
0
 public CollbratorModel AddCollaboratorToNotes(CollbratorResponse collaborator, long UserId, long NoteId)
 {
     try
     {
         var result = this.icollabratorRL.AddCollaboratorToNotes(collaborator, UserId, NoteId);
         return(result);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
        public IActionResult AddColloborator(CollbratorResponse collaborator, long NoteId)
        {
            try
            {
                var identity = User.Identity as ClaimsIdentity;
                if (identity != null)
                {
                    IEnumerable <Claim> claims = identity.Claims;
                    long            UserID     = Convert.ToInt64(claims.Where(p => p.Type == "UserId").FirstOrDefault()?.Value);
                    string          Email      = claims.Where(p => p.Type == "Email").FirstOrDefault()?.Value;
                    CollbratorModel result     = this.collaboratorBL.AddCollaboratorToNotes(collaborator, UserID, NoteId);
                    if (result != null)
                    {
                        return(this.Ok(new { Message = result }));
                    }
                }

                return(BadRequest());
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }