public IList <UserModel> loadUsers() { IList <UserModel> _users = null; using (var context = new GARSupport2020Entities()) { _users = context.Users .Select(userItem => new UserModel() { Id = userItem.id, Name = userItem.name, FirstName = userItem.first_name, SecondName = userItem.second_name, Address = userItem.address, Phone = userItem.phone, SecondContact = userItem.second_contact, Email = userItem.email, Password = userItem.password }).ToList <UserModel>(); if (_users.Count == 0) { return(null); } return(_users); } }
public IHttpActionResult GetById(int id) { IList<CommentModel> comment = null; using (var context = new GARSupport2020Entities()) { comment = context.Comment .Where(commentItem => commentItem.id_issue == id) .Select(commentItem => new CommentModel() { Id = commentItem.id, Id_Issue = commentItem.id_issue, Name = commentItem.name, Description = commentItem.description, Time_Stamp = commentItem.time_stamp } ).ToList<CommentModel>(); } if (comment == null) { return NotFound(); } return Ok(comment); }
public IHttpActionResult GetAllUsers() { IList <UserModel> user = null; using (var context = new GARSupport2020Entities()) { user = context.Users .Select(userItem => new UserModel() { Id = userItem.id, Name = userItem.name, SecondName = userItem.second_name, FirstName = userItem.first_name, Address = userItem.address, Phone = userItem.phone, SecondContact = userItem.second_contact, Email = userItem.email, Password = userItem.password }).ToList <UserModel>(); } if (user.Count == 0) { return(NotFound()); } return(Ok(user)); }
public IHttpActionResult Post(IssueModel issue) { using (var context = new GARSupport2020Entities()) { context.Issue.Add(new Issue() { id = issue.Id, id_client = issue.Id_Client, description = issue.Description, time_stamp = issue.Time_Stamp, contact_phone = issue.Contact_Phone, contact_email = issue.Contact_Email, classification = issue.Classification, status = issue.Status, service_type = issue.Service_Type, name = issue.Name, second_name = issue.Second_Name, first_name = issue.First_Name, address = issue.Address, phone = issue.Phone, second_contact = issue.Second_contact, email = issue.Email }); context.SaveChanges(); } return(Ok()); }
public IHttpActionResult GetDetailsById(int id) { IssueModel issue = null; using (var context = new GARSupport2020Entities()) { issue = context.Issue .Where(issueItem => issueItem.id == id) .Select(issueItem => new IssueModel() { Id = issueItem.id, Id_Client = issueItem.id_client, Description = issueItem.description, Time_Stamp = issueItem.time_stamp, Contact_Phone = issueItem.contact_phone, Contact_Email = issueItem.contact_email, Classification = issueItem.classification, Status = issueItem.status, Service_Type = issueItem.service_type, Name = issueItem.name, First_Name = issueItem.first_name, Second_Name = issueItem.second_name, Address = issueItem.address, Phone = issueItem.phone, Second_contact = issueItem.second_contact, Email = issueItem.email } ).FirstOrDefault <IssueModel>(); } if (issue == null) { return(NotFound()); } return(Ok(issue)); }
public IHttpActionResult Post(UsersIssueModel usersIssue) { using (var context = new GARSupport2020Entities()) { context.Users_Issue.Add(new Users_Issue() { id = usersIssue.Id, id_users = usersIssue.Id_Users, id_issue = usersIssue.Id_Issue }); context.SaveChanges(); } return(Ok()); }
public IHttpActionResult GetById(int id) { IList <IssueModel> issue = null; IList <UsersIssueModel> usersIssue = null; using (var context = new GARSupport2020Entities()) { usersIssue = context.Users_Issue .Where(usersIssueItem => usersIssueItem.id_users == id) .Select(usersIssueItem => new UsersIssueModel() { Id_Issue = usersIssueItem.id_issue } ).ToList <UsersIssueModel>(); } using (var context = new GARSupport2020Entities()) { foreach (var id_issue in usersIssue) { issue = context.Issue .Where(issueItem => issueItem.id == id_issue.Id_Issue) .Select(issueItem => new IssueModel() { Id = issueItem.id, Id_Client = issueItem.id_client, Description = issueItem.description, Time_Stamp = issueItem.time_stamp, Contact_Phone = issueItem.contact_phone, Contact_Email = issueItem.contact_email, Classification = issueItem.classification, Status = issueItem.status, Service_Type = issueItem.service_type, Name = issueItem.name, First_Name = issueItem.first_name, Second_Name = issueItem.second_name, Address = issueItem.address, Phone = issueItem.phone, Second_contact = issueItem.second_contact, Email = issueItem.email }).ToList <IssueModel>(); } } if (issue == null) { return(NotFound()); } return(Ok(issue)); }
public IHttpActionResult Post(CommentModel comment) { using (var context = new GARSupport2020Entities()) { context.Comment.Add(new Comment() { id = comment.Id, id_issue = comment.Id_Issue, name = comment.Name, description = comment.Description, time_stamp = comment.Time_Stamp }); context.SaveChanges(); } return Ok(comment); }
public IHttpActionResult GetAllSupports() { IList <UserModel> user = null; IList <UsersRoleModel> usersRole = null; using (var context = new GARSupport2020Entities()) { usersRole = context.User_Role .Where(usersRoleItem => usersRoleItem.id_role == 2) .Select(usersRoleItem => new UsersRoleModel() { Id_Users = usersRoleItem.id_users }).ToList <UsersRoleModel>(); } using (var context = new GARSupport2020Entities()) { foreach (var id_users in usersRole) { user = context.Users .Where(userItem => userItem.id == id_users.Id_Users) .Select(userItem => new UserModel() { Id = userItem.id, Name = userItem.name, SecondName = userItem.second_name, FirstName = userItem.first_name, Address = userItem.address, Phone = userItem.phone, SecondContact = userItem.second_contact, Email = userItem.email, Password = userItem.password }).ToList <UserModel>(); } } if (user.Count == 0) { return(NotFound()); } return(Ok(user)); }
public IHttpActionResult GetAll() { IList <UsersIssueModel> issues = null; using (var context = new GARSupport2020Entities()) { issues = context.Users_Issue .Select(issueItem => new UsersIssueModel() { Id = issueItem.id, Id_Users = issueItem.id_users, Id_Issue = issueItem.id_issue }).ToList <UsersIssueModel>(); } if (issues.Count == 0) { return(NotFound()); } return(Ok(issues)); }
public IHttpActionResult GetById(int id) { IList <UsersRoleModel> usersRoles = null; using (var context = new GARSupport2020Entities()) { usersRoles = context.User_Role .Where(usersRole => usersRole.id_users == id) .Select(usersRole => new UsersRoleModel() { Id = usersRole.id, Id_Role = usersRole.id_role, Id_Users = usersRole.id_users } ).ToList <UsersRoleModel>(); } if (usersRoles == null) { return(NotFound()); } return(Ok(usersRoles)); }
public IHttpActionResult Post(IList <UsersRoleModel> usersRole) { int count = 0; IList <UsersRoleModel> newUsersRoles = null; IList <UsersRoleModel> support = null; using (var context = new GARSupport2020Entities()) { foreach (var role in usersRole) { if (count == 0) { //verifica si ya existe newUsersRoles = context.User_Role .Where(usersRoleItem => usersRoleItem.id_users == role.Id_Users) .Select(usersRoleItem => new UsersRoleModel() { Id_Role = usersRoleItem.id_role, Id_Users = usersRoleItem.id_users } ).ToList <UsersRoleModel>(); //Si existe lo borra if (newUsersRoles != null) { foreach (var delete in newUsersRoles) { var deleteRole = context.User_Role.Where(userItem => userItem.id_users == delete.Id_Users).FirstOrDefault(); context.Entry(deleteRole).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } } } count++; context.User_Role.Add(new User_Role() { id = role.Id, id_users = role.Id_Users, id_role = role.Id_Role }); context.SaveChanges(); } foreach (var id_user in usersRole) { support = context.User_Role .Where(usersRoleItem => usersRoleItem.id_users == id_user.Id_Users) .Select(usersRoleItem => new UsersRoleModel() { Id_Users = usersRoleItem.id_users, Id_Role = usersRoleItem.id_role }).ToList <UsersRoleModel>(); } //Si el valor es nulo if (support == null) { foreach (var delete in usersRole) { ///No es sopporte? // Verifica si en la tabla userIssue ya tiene un issue asignado var userDeleted = context.Users_Issue .Where(usersIssueItem => usersIssueItem.id_users == delete.Id_Users) .Select(usersIssueItem => new UsersIssueModel() { Id_Users = usersIssueItem.id_users, }).FirstOrDefault(); // Si existe entra if (userDeleted != null) { var deleteUser = context.Users_Issue.Where(userItem => userItem.id_users == delete.Id_Users).FirstOrDefault(); context.Entry(deleteUser).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } } } else { foreach (var role in support) { ///No es sopporte? if (role.Id_Role != 2) { // Verifica si en la tabla userIssue ya tiene un issue asignado var issueUser = context.Users_Issue .Where(usersIssueItem => usersIssueItem.id_users == role.Id_Users) .Select(usersIssueItem => new UsersIssueModel() { Id_Users = usersIssueItem.id_users, }).FirstOrDefault(); // Si existe entra if (issueUser != null) { var deleteUser = context.Users_Issue.Where(userItem => userItem.id_users == role.Id_Users).FirstOrDefault(); context.Entry(deleteUser).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } } } } } return(Ok()); }