Esempio n. 1
0
        // PUT: api/Actions/5
        public HttpResponseMessage Post([FromBody] List <APIModels.Action> actions)
        {
            try
            {
                foreach (APIModels.Action a in actions)
                {
                    int broj = 0;
                    using (ChangeCodeEntities db = new ChangeCodeEntities())
                    {
                        broj = db.Actions.Where(l => l.ActionName == a.ActionName).ToList().Count();
                    }

                    if (broj == 0)
                    {
                        Actions akcija = Mapper.Map <Actions>(a);
                        akcija.ID = Guid.NewGuid();
                        if (!string.IsNullOrEmpty(akcija.ActionImage))
                        {
                            akcija.DateBegin = akcija.DateBegin == DateTime.MinValue ? null : akcija.DateBegin;
                            akcija.DateEnd   = akcija.DateEnd == DateTime.MinValue ? null : akcija.DateEnd;


                            using (ChangeCodeEntities db = new ChangeCodeEntities())
                            {
                                db.Actions.Add(akcija);
                                db.SaveChanges();
                            }

                            string       tweetID = akcija.ActionURL.Split('/').LastOrDefault();
                            string       handle  = akcija.UserURL.Split('/').LastOrDefault();
                            ProcessTools pt      = new ProcessTools();
                            pt.pokreniProces("python", "c:/Micro/PostTweets.py " + tweetID + " " + akcija.ActionUserID + " " + handle);
                        }
                    }
                }

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 2
0
        public ActionResult Detalji(Guid id)
        {
            using (ChangeCodeEntities db = new ChangeCodeEntities())
            {
                ViewData["TrenutniKorisnik"] = CurrentUser.DohvatiTrenutnog();

                Actions a       = db.Actions.Where(l => l.ID == id).FirstOrDefault();
                string  tweetID = a.ActionURL.Split('/').LastOrDefault();

                ProcessTools pt = new ProcessTools();
                pt.pokreniProces("python", "c:/Micro/TwitterAnalytics.py " + tweetID);
                Thread.Sleep(5000);
                if (a != null)
                {
                    ViewData["Akcija"] = a;
                    ViewData["Stat"]   = db.ActionStats.Where(l => l.IDAction == a.ID).OrderBy(l => l.Date).ToList().LastOrDefault();

                    System.Web.HttpRequest context = System.Web.HttpContext.Current.Request;
                    HttpCookie             kuki    = context.Cookies["Sessionid"];
                    string token = "";
                    if (kuki != null)
                    {
                        token = kuki.Value;
                    }
                    List <UserAction> listaKorisnika = db.UserAction.Where(l => l.IDAction == a.ID && l.Dosao == true).ToList();

                    List <Users> dosliKorisnici = new List <Users>();

                    foreach (UserAction ua in listaKorisnika)
                    {
                        Users temp = db.Users.Where(l => l.ID == ua.IDUser).FirstOrDefault();
                        if (temp != null)
                        {
                            dosliKorisnici.Add(temp);
                        }
                    }

                    ViewData["DosliKorisnici"] = dosliKorisnici;


                    Users trenutniKorisnik = db.Users.Where(l => l.UserKey.Contains(token)).FirstOrDefault();

                    if (trenutniKorisnik != null)
                    {
                        string userName = a.UserURL.Split('/').LastOrDefault();
                        if (trenutniKorisnik.Email == userName)
                        {
                            ViewBag.UserAdmin = true;
                        }
                        ViewBag.Korisnik   = db.UserAction.Where(l => l.IDAction == a.ID && l.IDUser == trenutniKorisnik.ID).FirstOrDefault();
                        ViewBag.KorisnikID = trenutniKorisnik.ID;
                        ViewBag.ActionID   = a.ID;
                    }
                    else
                    {
                        ViewBag.Korisnik = null;
                    }
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound, ""));
                }
            }
            return(View());
        }
Esempio n. 3
0
        public void Get()
        {
            ProcessTools pt = new ProcessTools();

            pt.pokreniProces("python", @"C:\Micro\OCRApplication\pokreni.py");
        }