public IHttpActionResult CreateUser(string token, JDE_Users jDE_Users, int UserId) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { jDE_Users.TenantId = tenants.FirstOrDefault().TenantId; db.JDE_Users.Add(jDE_Users); db.SaveChanges(); JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Utworzenie użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(jDE_Users) }; db.JDE_Logs.Add(Log); db.SaveChanges(); return(Ok(jDE_Users)); //return CreatedAtRoute("DefaultApi", new { id = jDE_Users.UserId }, jDE_Users); } else { return(NotFound()); } } else { return(NotFound()); } }
public HttpResponseMessage ArchiveUser(string token, int id, int UserId) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { var items = db.JDE_Users.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == id); if (items.Any()) { JDE_Users orgItem = items.FirstOrDefault(); orgItem.IsArchived = true; JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Archiwizacja użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = "" }; db.JDE_Logs.Add(Log); try { db.Entry(orgItem).State = EntityState.Modified; db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JDE_UsersExists(id)) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } else { throw; } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } } } } return(Request.CreateResponse(HttpStatusCode.NoContent)); }
public IHttpActionResult LogIn(string token, int id, JDE_Users jDE_Users) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { var users = db.JDE_Users.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == id); if (users.Any()) { JDE_Logs Log = new JDE_Logs { UserId = id, Description = "Logowanie", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now }; jDE_Users.lastLoggedOn = DateTime.Now; db.Entry(jDE_Users).State = EntityState.Modified; db.JDE_Logs.Add(Log); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JDE_UsersExists(id)) { return(NotFound()); } else { throw; } } } } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult EditUser(string token, int id, int UserId, JDE_Users jDE_Users) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { var users = db.JDE_Users.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == id); if (users.Any()) { JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Edycja użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(users.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(jDE_Users) }; db.JDE_Logs.Add(Log); db.Entry(jDE_Users).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JDE_UsersExists(id)) { return(NotFound()); } else { throw; } } } } } return(StatusCode(HttpStatusCode.NoContent)); }