//public Tuple <List<tblLabel>,List<tblLabelNotes>>labelshow(tblLabelNotes objtbl,string userid)
        //{
        //    Tuple<List<tblLabel>,List<tblLabelNotes>> result = null;
        //    result = noteService.labelshow(objtbl, userid);
        //    return result;
        //}

        public async Task <string> labelshow(tblLabelNotes objtbl)
        {
            Tuple <List <tblLabel>, List <tblLabelNotes>, List <tblCollaborator> > result = null;

            result = noteService.labelshow(objtbl, objtbl.UserID);
            string JSONString;

            JSONString = JsonConvert.SerializeObject(result);

            return(JSONString);
        }
Beispiel #2
0
        //public string labelshow()
        //{
        //    tblLabelNotes objtbl = new tblLabelNotes();
        //    string userid=TempData["UserID"].ToString();
        //    Tuple<List<tblLabel>, List<tblLabelNotes>> result=null;
        //    //int result = 0;
        //    if (ModelState.IsValid)
        //    {
        //        result = notesApicontroller.labelshow(objtbl, userid);
        //    }
        //    string JSONString;
        //    JSONString = JsonConvert.SerializeObject(result);

        //    return JSONString;
        //}
        public async Task <string> labelshow()
        {
            token = TempData["access_token"].ToString();
            TempData.Keep();
            tblNotes obj = new tblNotes();

            obj.UserID = UserId;
            int    result1 = 0;
            string re      = string.Empty;
            // Tuple<List<tblLabel>, List<tblLabelNotes>> result = null;
            string ABC = "";


            tblLabelNotes objtbl = new tblLabelNotes();
            string        userid = TempData["UserID"].ToString();

            objtbl.UserID = userid;
            string myString;

            if (External != "Log")
            {
                ABC = await notesApicontroller.labelshow(objtbl);

                myString = ABC;
            }
            else
            {
                ABC = await accountController.ConsumePostchipApi(objtbl, token);

                ABC      = ABC.Replace("\\", "");
                myString = ABC;

                myString = myString.Substring(0, myString.Length - 1);
                int index1 = myString.IndexOf('"');
                if (index1 != -1)
                {
                    myString = myString.Remove(index1, 1);
                }
            }

            // Tuple<List<tblLabel>, List<tblLabelNotes>> result=null;
            //int result = 0;
            //if (ModelState.IsValid)
            //{
            //    result = notesApicontroller.labelshow(objtbl, userid);
            //}
            //string JSONString;
            // JSONString = JsonConvert.SerializeObject(ABC);

            return(myString);
        }
Beispiel #3
0
        public async Task <string> ConsumePostchipApi(tblLabelNotes model, string token)
        {
            try
            {
                var    client    = new HttpClient();
                string returnurl = currenturl + "/api/NotesApi/labelshow";

                client.BaseAddress = new Uri(returnurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);



                //var response = await client.GetAsync(returnurl);
                //var contents = await response.Content.ReadAsStringAsync();
                //var data = JsonConvert.DeserializeObject<List<tblLabelNotes>>(contents);

                var body = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("ID", Convert.ToString(model.ID)),
                    new KeyValuePair <string, string>("LabelID", model.LabelID),
                    new KeyValuePair <string, string>("UserID", Convert.ToString(model.UserID)),
                    new KeyValuePair <string, string>("NotesID", Convert.ToString(model.NotesID))
                };
                //var content = new FormUrlEncodedContent(body);
                var response = await client.PostAsync(returnurl, new FormUrlEncodedContent(body));

                // var response = await httpClient.PostAsync(returnurl, new FormUrlEncodedContent(body));

                var contents = await response.Content.ReadAsStringAsync();

                return(contents);
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());;
            }
            return("");
        }
Beispiel #4
0
        public Tuple <List <tblLabel>, List <tblLabelNotes>, List <tblCollaborator> > labelshow(tblLabelNotes objtbl, string userid)
        {
            int result = 0;
            //List<tblLabel> response =new List<tblLabel>();


            var lbl          = new List <tblLabel>();
            var lblname      = new List <tblLabelNotes>();
            var Collaborator = new List <tblCollaborator>();

            ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            //current user check in share colum tblCollaborators tbl
            var share = from t in applicationDbContext.tblCollaborators
                        where t.SharID == user.Email
                        select t;

            var sharelist = new List <tblCollaborator>();

            foreach (tblCollaborator data1 in share)
            {
                sharelist.Add(data1);
            }
            var temp = new List <tblNotes>();

            for (int i = 0; i < sharelist.Count(); i++)
            {
                int id        = sharelist[i].NotesID;
                var sharedata = from t in applicationDbContext.tblNotes
                                where t.ID == id
                                select t;
                foreach (tblNotes data12 in sharedata)
                {
                    temp.Add(data12);
                }
            }

            for (int i = 0; i < temp.Count(); i++)
            {
                string userid1 = temp[i].UserID;
                int    nodeid  = temp[i].ID;
                var    data1   = from a in applicationDbContext.tblLabelNotes
                                 where a.UserID == userid1 && a.NotesID == nodeid
                                 select a;

                foreach (tblLabelNotes itemdata in data1)
                {
                    lblname.Add(itemdata);
                }

                var newdata12 = from a in applicationDbContext.tblCollaborators
                                where a.UserID == userid1 && a.NotesID == nodeid && a.SharID == user.Email
                                select a;
                foreach (tblCollaborator itm in newdata12)
                {
                    //change email for share
                    var own = itm.OwnerID;
                    var sh  = itm.SharID;

                    itm.SharID  = own;
                    itm.OwnerID = sh;
                    Collaborator.Add(itm);
                }
            }



            var data = from a in applicationDbContext.tblLabelNotes
                       where a.UserID == userid
                       select a;

            foreach (tblLabelNotes itemdata in data)
            {
                lblname.Add(itemdata);
            }


            for (int i = 0; i < lblname.Count; i++)
            {
                var id      = int.Parse(lblname[i].LabelID.ToString());
                var newdata = from a in applicationDbContext.tblLabels
                              where a.ID == id
                              select a;

                foreach (tblLabel itemdata in newdata)
                {
                    lbl.Add(itemdata);
                }
            }



            var newdata1 = from a in applicationDbContext.tblCollaborators
                           where a.UserID == userid
                           select a;

            foreach (tblCollaborator itm in newdata1)
            {
                Collaborator.Add(itm);
            }

            return(Tuple.Create(lbl, lblname, Collaborator));
        }
Beispiel #5
0
        public async Task <int> addnotelabel(tblNotes objtbl)
        {
            int result = 0;
            // Add new label.
            var listlabels = new List <int>();
            var labelnames = new List <string>();

            if (objtbl.Mode == 1)
            {
                try
                {
                    var labels = objtbl.Label.Split(',');

                    foreach (string data in labels)
                    {
                        labelnames.Add(data);
                    }

                    foreach (string item in labelnames)
                    {
                        var iddata = from a in applicationDbContext.tblLabels
                                     where a.Label == item
                                     select a;
                        foreach (tblLabel itemdata in iddata)
                        {
                            listlabels.Add(itemdata.ID);
                        }
                    }

                    for (int i = 0; i < listlabels.Count(); i++)
                    {
                        string cn    = listlabels[i].ToString();
                        var    check = from a in applicationDbContext.tblLabelNotes
                                       where a.NotesID == objtbl.ID && a.LabelID == cn
                                       select a;

                        if (check.Count() == 0)
                        {
                            tblLabelNotes label = new tblLabelNotes();

                            label.LabelID = cn;
                            label.NotesID = objtbl.ID;
                            label.UserID  = objtbl.UserID;
                            applicationDbContext.tblLabelNotes.Add(label);
                            result = await applicationDbContext.SaveChangesAsync();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }

                return(result);
            }

            if (objtbl.Mode == 2)
            {
                var iddata = from a in applicationDbContext.tblLabels
                             where a.Label == objtbl.Label
                             select a;
                foreach (tblLabel itemdata in iddata)
                {
                    listlabels.Add(itemdata.ID);
                }

                var           abc = listlabels[0].ToString();
                tblLabelNotes obj = applicationDbContext.tblLabelNotes.Where(i => i.LabelID == abc && i.NotesID == objtbl.ID).FirstOrDefault();
                applicationDbContext.tblLabelNotes.Remove(obj);

                result = await applicationDbContext.SaveChangesAsync();
            }

            if (objtbl.Mode == 3)
            {
                try
                {
                    var latestid = from a in applicationDbContext.tblNotes
                                   orderby a.ID descending
                                   select a.ID;
                    var id = latestid.First();

                    var newrecord = from a in applicationDbContext.tblLabelNotes
                                    where a.UserID == objtbl.UserID && a.NotesID == objtbl.ID
                                    select a;
                    var list = new List <string>();
                    foreach (tblLabelNotes tbl in newrecord)
                    {
                        list.Add(tbl.LabelID);
                    }

                    for (int i = 0; i < list.Count(); i++)
                    {
                        tblLabelNotes label = new tblLabelNotes();

                        label.LabelID = list[i];
                        label.NotesID = id;
                        label.UserID  = objtbl.UserID;
                        applicationDbContext.tblLabelNotes.Add(label);
                        result = await applicationDbContext.SaveChangesAsync();
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }

                return(result);
            }
            return(result);
        }