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")); }
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")); }