public IHttpActionResult PutUserSession(int id, UserSession userSession)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != userSession.ID)
            {
                return BadRequest();
            }

            db.Entry(userSession).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserSessionExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostUserSession(UserSession userSession)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.UserSession.Add(userSession);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = userSession.ID }, userSession);
        }
Exemplo n.º 3
0
        public ActionResult Config(int id)
        {
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            if (Request.IsAuthenticated)
            {
                if (!userManager.IsInRole(User.Identity.GetUserId(), "Configuration") && !userManager.IsInRole(User.Identity.GetUserId(), "System Admin"))
                {
                    return RedirectToAction("AccessBlock", "Account", new { area = "" });
                }
                else
                {
                    CalcConfiguration ProjectBoard = db.CalcConfiguration.Find(Convert.ToInt32(id));
                    var List = db.UserSession.Where(i => i.Record == id);
                    if (List.Count() == 0)
                    {
                        UserSession UsersessionAdd = new UserSession();
                        UsersessionAdd.Section = "Calculation";
                        UsersessionAdd.Record = id;
                        UsersessionAdd.StartTime = DateTime.Now;
                        UsersessionAdd.Username = HttpContext.User.Identity.Name.ToString();
                        db.UserSession.Add(UsersessionAdd);
                        db.SaveChanges();
                    }

                    try
                    {
                        ViewData["SchemeName"] = ProjectBoard.Scheme;
                        ViewData["CalcName"] = ProjectBoard.Name;

                    }
                    catch
                    {

                    }
                    return View();
                }
            }
            else
            {
                return RedirectToAction("Login", "Account", new { area = "" });
            }
        }