Exemplo n.º 1
0
        public IActionResult AddCollaborator([FromBody] ApplicationUser model)
        {
            ActionResult response = null;

            try
            {
                var user = from a in _context.Users
                           where a.Email == model.Email
                           select a;

                string userid = String.Empty;
                foreach (ApplicationUser item in user)
                {
                    userid = item.Id;
                }

                tblCollborator coll = new tblCollborator();
                coll.noteid = Convert.ToInt32(model.postalcode);
                coll.Userid = userid;
                _context.tblCollaborator.Add(coll);
                int j = _context.SaveChanges();

                var colluser = from a in _context.tblCollaborator
                               where a.Userid == userid
                               select a;
                int collid = 0;
                foreach (tblCollborator item in colluser)
                {
                    collid = item.Id;
                }
                tblUserCollaborate collnew = new tblUserCollaborate();
                collnew.collaboratorId = collid;
                collnew.userid         = model.aadharno;
                _context.tblUserCollaborates.Add(collnew);
                int i = _context.SaveChanges();
                response = Ok(new { status = "Collaborator added successfully" });
            }
            catch (Exception ex)
            {
                ex.ToString();
                response = Ok(new { status = ex.ToString() });
            }

            return(response);
        }
Exemplo n.º 2
0
        public IActionResult PostAllCollaborator([FromBody] ApplicationUser model)
        {
            //aadharno=userid
            //postalcode=noteid
            //email=email


            IActionResult response             = null;
            var           validuser            = new List <ApplicationUser>();
            var           ownernote            = new List <tblNotes>();
            string        collaborateid        = String.Empty;
            int           collatesharedid      = 0;
            var           sharedcollaboratorid = new List <int>();

            try
            {
                //verify user is registered or not
                var valid = from a in _context.Users
                            where a.Email == model.Email
                            select a;
                foreach (ApplicationUser item in valid)
                {
                    validuser.Add(item);
                    collaborateid = item.Id;
                }
                if (validuser.Count > 0)
                {
                    var owner = from b in _context.tblNotes
                                where b.Id == Convert.ToInt32(model.postalcode) && b.UserId == model.aadharno
                                select b;
                    foreach (tblNotes item in owner)
                    {
                        ownernote.Add(item);
                    }
                    if (ownernote.Count > 0)
                    {
                        tblCollborator coll = new tblCollborator();
                        coll.Userid = collaborateid;
                        coll.noteid = Convert.ToInt32(model.postalcode);
                        _context.tblCollaborator.Add(coll);
                        int i = _context.SaveChanges();

                        var collaboratordata = from c in _context.tblCollaborator
                                               where c.Userid == collaborateid
                                               select c;

                        foreach (tblCollborator item in collaboratordata)
                        {
                            sharedcollaboratorid.Add(item.Id);
                        }

                        foreach (int data in sharedcollaboratorid)
                        {
                            tblUserCollaborate usercoll = new tblUserCollaborate();
                            usercoll.collaboratorId = data;
                            usercoll.userid         = model.aadharno;
                            _context.tblUserCollaborates.Add(usercoll);
                            int j = _context.SaveChanges();
                        }
                    }
                    else
                    {
                        tblCollborator coll = new tblCollborator();
                        coll.Userid = collaborateid;
                        coll.noteid = Convert.ToInt32(model.postalcode);
                        _context.tblCollaborator.Add(coll);
                        int i = _context.SaveChanges();

                        var tblCollData = from d in _context.tblCollaborator
                                          where d.noteid == coll.noteid
                                          select d;

                        foreach (tblCollborator item in tblCollData)
                        {
                            collatesharedid = item.Id;
                        }

                        var findowner = (from e in _context.tblCollaborator
                                         join f in _context.tblUserCollaborates
                                         on e.Id equals f.collaboratorId
                                         select new { e.noteid, e.Userid, f.collaboratorId, f.userid }).ToList();


                        foreach (var item in findowner)
                        {
                            tblUserCollaborate usercoll = new tblUserCollaborate();
                            usercoll.userid         = item.userid;
                            usercoll.collaboratorId = collatesharedid;
                            _context.tblUserCollaborates.Add(usercoll);
                            int k = _context.SaveChanges();
                        }
                    }

                    response = Ok(new { owner = ownernote, status = "owner" });
                }
                else
                {
                    return(response = Ok(new { ErrorMessage = "User is not registered so note cannot be shared" }));
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }


            return(response);
        }