示例#1
0
        public async Task <ActionResult> DodajSliku(HttpPostedFileBase file, string id)//
        {
            if (file != null && file.ContentLength > 0)
            {
                string temp = Guid.NewGuid().ToString();
                string path = Path.Combine(Server.MapPath("~/Content/"),
                                           (temp + "." + file.ContentType.Split('/').Last()));
                file.SaveAs(path);

                byte[] fileR = System.IO.File.ReadAllBytes(path);

                List <string> guidi = await Task.Run(() => IdentifyFace.identifyFace(Convert.ToBase64String(fileR)));

                Thread.Sleep(5000);
                foreach (string t in guidi)
                {
                    Guid uID = new Guid(t);
                    Guid aID = new Guid(id);

                    using (ChangeCodeEntities db = new ChangeCodeEntities())
                    {
                        UserAction ua = db.UserAction.Where(l => l.IDAction == aID && l.IDUser == uID).FirstOrDefault();
                        if (ua == null)
                        {
                            ua          = new UserAction();
                            ua.ID       = Guid.NewGuid();
                            ua.IDAction = aID;
                            ua.IDUser   = uID;
                            ua.Dosao    = true;
                            db.UserAction.Add(ua);
                            db.SaveChanges();
                        }
                        else
                        {
                            ua.Dosao           = true;
                            db.Entry(ua).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                System.IO.File.Delete(path);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "Please select file";
            }
            ViewBag.ID = id;
            return(RedirectToAction("Index", "Home"));
        }
示例#2
0
        public async System.Threading.Tasks.Task <ActionResult> Login(string token, string username)
        {
            try
            {
                using (ChangeCodeEntities db = new ChangeCodeEntities())
                {
                    Users korisnik = db.Users.Where(l => l.Email == username).FirstOrDefault();

                    if (korisnik != null)
                    {
                        ViewBag.Success = true;

                        HttpContext ctx = System.Web.HttpContext.Current;

                        HttpCookie cookie = new HttpCookie("Sessionid");
                        cookie.HttpOnly = true;
                        string tok = token;
                        cookie.Value   = token;
                        cookie.Expires = DateTime.Now.AddDays(1);

                        ctx.Response.SetCookie(cookie);

                        korisnik.Token           = tok;
                        db.Entry(korisnik).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        korisnik         = new Users();
                        korisnik.ID      = Guid.NewGuid();
                        korisnik.Email   = username;
                        korisnik.UserKey = token;

                        string tok = Hash.HashSHA512(token + korisnik.Email);

                        db.Users.Add(korisnik);
                        db.SaveChanges();

                        return(RedirectToAction("Registracija/" + korisnik.ID, "Start"));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#3
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));
            }
        }
        public HttpResponseMessage Post([FromBody] APIModels.ActionStat actions)
        {
            try
            {
                using (ChangeCodeEntities db = new ChangeCodeEntities())
                {
                    actions.IDAction = db.Actions.Where(l => l.ActionURL.Contains(actions.IDStatus)).FirstOrDefault().ID;
                    ActionStats akcija = Mapper.Map <ActionStats>(actions);
                    akcija.ID   = Guid.NewGuid();
                    akcija.Date = DateTime.Now;

                    db.ActionStats.Add(akcija);
                    db.SaveChanges();
                }



                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
示例#5
0
        public ActionResult Detalji(string userid, string actionid)
        {
            Guid userGUID   = new Guid(userid);
            Guid actionGUID = new Guid(actionid);

            ViewBag.UserAdmin = null;
            using (ChangeCodeEntities db = new ChangeCodeEntities())
            {
                ViewData["TrenutniKorisnik"] = CurrentUser.DohvatiTrenutnog();

                UserAction ua = db.UserAction.Where(l => l.IDAction == actionGUID && l.IDUser == userGUID).FirstOrDefault();
                if (ua == null)
                {
                    ua          = new UserAction();
                    ua.ID       = Guid.NewGuid();
                    ua.IDAction = actionGUID;
                    ua.IDUser   = userGUID;

                    db.UserAction.Add(ua);
                    db.SaveChanges();
                }

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

                ProcessTools pt = new ProcessTools();
                pt.pokreniProces("python", "c:/Micro/TwitterAnalytics.py " + tweetID);

                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 uac in listaKorisnika)
                    {
                        Users temp = db.Users.Where(l => l.ID == uac.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());
        }