public IHttpActionResult CreateActionType(string token, JDE_ActionTypes item, int UserId) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { item.TenantId = tenants.FirstOrDefault().TenantId; db.JDE_ActionTypes.Add(item); db.SaveChanges(); JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Utworzenie typu złoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item) }; db.JDE_Logs.Add(Log); db.SaveChanges(); return(Ok(item)); //return CreatedAtRoute("DefaultApi", new { id = item.ActionTypeId }, item); } else { return(NotFound()); } } else { return(NotFound()); } }
public IHttpActionResult GetActionTypeByName(string token, string name, int UserId) { if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { if (JDE_ActionTypesExists(name)) { //there's action type of given name, return it var item = db.JDE_ActionTypes.Where(i => i.Name.Equals(name.Trim())).FirstOrDefault(); return(Ok(item)); } else { //there's NO action type of given name, create it and return it JDE_ActionTypes nAt = new JDE_ActionTypes { Name = name.Trim(), Description = null, MesSync = true, RequireInitialDiagnosis = true, ShowInPlanning = false, AllowDuplicates = true, RequireQrToStart = false, RequireQrToFinish = false, ClosePreviousInSamePlace = false, PartsApplicable = false, ActionsApplicable = false, RequireUsersAssignment = false, ShowOnDashboard = false, Leaveable = true, CreatedBy = UserId, CreatedOn = DateTime.Now, TenantId = tenants.FirstOrDefault().TenantId }; db.JDE_ActionTypes.Add(nAt); db.SaveChanges(); JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Utworzenie typu złoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(nAt) }; db.JDE_Logs.Add(Log); db.SaveChanges(); return(Ok(nAt)); } } else { return(NotFound()); } } else { return(NotFound()); } }
public IHttpActionResult EditActionType(string token, int id, JDE_ActionTypes item, 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_ActionTypes.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.ActionTypeId == id); if (items.Any()) { JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Edycja typu zgłoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(item) }; db.JDE_Logs.Add(Log); db.Entry(item).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JDE_ActionTypesExists(id)) { return(NotFound()); } else { throw; } } } } } return(StatusCode(HttpStatusCode.NoContent)); }