public bool Delete(Guid UserId) { User User = IMSContext.Users.Where(u => u.Id == UserId).FirstOrDefault(); if (User == null) { throw new BadRequestException("User không tồn tại."); } IMSContext.Users.Remove(User); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity UserEntity, Guid Id) { HrEmployee HrEmployee = IMSContext.HrEmployees.Where(h => h.Id == Id).FirstOrDefault(); if (HrEmployee == null) { throw new BadRequestException("HrEmployee không tồn tại"); } IMSContext.HrEmployees.Remove(HrEmployee); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity UserEntity, Guid MessageId) { Message Message = IMSContext.Messages.Where(m => m.Id == MessageId).FirstOrDefault(); if (Message == null) { throw new BadRequestException("Message not found."); } IMSContext.Messages.Remove(Message); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity UserEntity, Guid studentId) { Student student = IMSContext.Students.Where(s => s.Id == studentId).FirstOrDefault(); if (student == null) { return(false); } IMSContext.Students.Remove(student); IMSContext.SaveChanges(); return(true); }
// Xóa Lecturer theo id public bool Delete(UserEntity UserEntity, Guid LecturerId) { Lecturer Lecturer = IMSContext.Lecturers.Where(l => l.Id == LecturerId).FirstOrDefault(); if (Lecturer == null) { throw new BadRequestException("Lecturer không tồn tại."); } IMSContext.Lecturers.Remove(Lecturer); IMSContext.SaveChanges(); return(true); }
public StudentEntity Update(UserEntity UserEntity, Guid StudentId, StudentEntity StudentEntity) { Student student = IMSContext.Students.Where(s => s.Id == StudentId).FirstOrDefault(); if (student == null) { throw new BadRequestException("User not found"); } StudentEntity.ToModel(student); IMSContext.SaveChanges(); return(new StudentEntity(student)); }
public bool Delete(UserEntity UserEntity, Guid OperationId) { Operation Operation = IMSContext.Operations.Where(l => l.Id == OperationId).FirstOrDefault(); if (Operation == null) { throw new BadRequestException("Operation không tồn tại."); } IMSContext.Operations.Remove(Operation); IMSContext.SaveChanges(); return(true); }
public bool Delete(Guid CompanyId) { Company Company = IMSContext.Companies.Where(c => c.Id == CompanyId).FirstOrDefault(); if (Company == null) { throw new BadRequestException("Company không tồn tại"); } IMSContext.Companies.Remove(Company); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity userEntity, Guid StudentId) { StudentLecturer studentLecturer = IMSContext.StudentLecturers.Where(sl => sl.StudentId == StudentId).FirstOrDefault(); if (studentLecturer == null) { throw new BadRequestException("StudentLecturer không tồn tại!"); } IMSContext.Remove(studentLecturer); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity UserEntity, Guid Id) { InternReport internReport = IMSContext.InternReports.Where(m => m.Id == Id).FirstOrDefault(); if (internReport == null) { throw new BadRequestException("Report not found."); } IMSContext.InternReports.Remove(internReport); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity userEntity, Guid Id) { Admin admin = IMSContext.Admins.Where(a => a.Id == Id).FirstOrDefault(); if (admin == null) { throw new BadRequestException("Admin không tồn tại!"); } IMSContext.Remove(admin); IMSContext.SaveChanges(); return(true); }
public void OnActionExecuting(ActionExecutingContext FilterContext) { if (FilterContext.HttpContext.Request.Path.Value.StartsWith("/Login")) { return; } var Token = FilterContext.HttpContext.Request.Cookies["JWT"]; var JWTEntity = JWTHandler.Decode(Token); if (JWTEntity != null) { FilterContext.HttpContext.User = new MyPrincipal(JWTEntity.UserEntity); string Path = FilterContext.HttpContext.Request.Path.HasValue ? FilterContext.HttpContext.Request.Path.Value : ""; string Method = FilterContext.HttpContext.Request.Method; string[] temp = Path.Split('/'); for (int i = 0; i < temp.Length; i++) { Guid id; bool isGuid = Guid.TryParse(temp[i], out id); if (isGuid) { temp[i] = "*"; } } return; Path = string.Join("/", temp); IMSContext IMSContext = new IMSContext(); Operation Operation = IMSContext.Operations.Where(o => o.Link.Equals(Path) && o.Method.Equals(Method)).FirstOrDefault(); if (Operation == null) { throw new ForbiddenException("Operation chưa được gán lên hệ thống"); } if (Operation.Role != 0) { int Role = (int)JWTEntity.UserEntity.Roles; if ((Operation.Role & Role) == 0) { throw new ForbiddenException("Bạn không có quyền truy cập"); } } return; } else { if (FilterContext.HttpContext.Request.Path.Value.StartsWith("api")) { throw new ForbiddenException("Cookie không hợp lệ"); } FilterContext.Result = new RedirectResult("/Login"); } }
public OperationEntity Create(UserEntity UserEntity, OperationEntity LecturerEntity) { Lecturer Lecturer = LecturerEntity.ToModel(); User User = new User() { Id = Lecturer.Id, Username = Lecturer.FullName, Password = "******" }; IMSContext.Users.Add(User); IMSContext.Lecturers.Add(Lecturer); IMSContext.SaveChanges(); return(LecturerEntity); }
public InternNewsEntity Update(UserEntity UserEntity, Guid internNewsId, InternNewsEntity internNewsEntity) { InternNews internNews = IMSContext.InternNews.Where(s => s.Id == internNewsId).FirstOrDefault(); if (internNews == null) { throw new BadRequestException("Khong tim thay Intern News"); } internNews = internNewsEntity.ToModel(internNews); IMSContext.InternNews.Update(internNews); IMSContext.SaveChanges(); return(internNewsEntity); }
public UserEntity Update(Guid UserId, UserEntity UserEntity) { User User = IMSContext.Users.Where(u => u.Id.Equals(UserEntity.Id)).FirstOrDefault(); if (User == null) { throw new BadRequestException("User không tồn tại."); } UserEntity.ToModel(User); User.Password = GetHashString(UserEntity.Password); IMSContext.SaveChanges(); return(new UserEntity(User)); }
public bool Delete(UserEntity UserEntity, Guid internNewsId) { InternNews internNews = IMSContext.InternNews.Where(s => s.Id == internNewsId).FirstOrDefault(); if (internNews == null) { return(false); } IMSContext.Remove(internNews); IMSContext.SaveChanges(); return(true); }
public AdminEntity Create(UserEntity userEntity, AdminEntity adminEntity) { Admin admin = adminEntity.ToModel(); User User = new User() { Id = admin.Id, Username = adminEntity.Fullname, Password = "******" }; IMSContext.Users.Add(User); IMSContext.Admins.Add(admin); IMSContext.SaveChanges(); return(adminEntity); }
public HrEmployeeEntity Create(UserEntity UserEntity, HrEmployeeEntity HrEmployeeEntity) { HrEmployee HrEmployee = HrEmployeeEntity.ToModel(); User User = new User() { Id = HrEmployee.Id, Username = HrEmployee.Name, Password = "******" }; IMSContext.Users.Add(User); IMSContext.HrEmployees.Add(HrEmployee); IMSContext.SaveChanges(); return(HrEmployeeEntity); }
public InternshipCourseEntity Update(UserEntity userEntity, Guid internshipCourseId, InternshipCourseEntity internshipCourseEntity) { Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); InternshipCourse internshipCourse = IMSContext.InternshipCourses.Where(s => s.Id == internshipCourseId).FirstOrDefault(); if (internshipCourse == null) { throw new BadRequestException("Khong tim thay course"); } internshipCourseEntity.ToModel(internshipCourse); IMSContext.SaveChanges(); return(new InternshipCourseEntity(internshipCourse)); }
// Tạo mới Lecturer public LecturerEntity Create(UserEntity UserEntity, LecturerEntity LecturerEntity) { Lecturer Lecturer = LecturerEntity.ToModel(); User User = new User(); User.Id = Lecturer.Id; User.Username = LecturerEntity.Username; User.Password = "******"; IMSContext.Users.Add(User); IMSContext.Lecturers.Add(Lecturer); IMSContext.SaveChanges(); return(Get(UserEntity, Lecturer.Id)); }
public InternshipCourseEntity Create(UserEntity userEntity, InternshipCourseEntity internshipCourseEntity) { InternshipCourse internshipCourse = internshipCourseEntity.ToModel(); Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); if (student == null) { throw new BadRequestException("user khong tim thay"); } student.InternshipCourses.Add(internshipCourse); IMSContext.InternshipCourses.Add(internshipCourse); IMSContext.SaveChanges(); return(new InternshipCourseEntity(internshipCourse)); }
public HrEmployeeEntity Create(UserEntity UserEntity, HrEmployeeEntity HrEmployeeEntity) { HrEmployee HrEmployee = HrEmployeeEntity.ToModel(); User user = new User(); user.Id = HrEmployee.Id; user.Username = HrEmployeeEntity.Username; user.Password = "******"; IMSContext.Users.Add(user); IMSContext.HrEmployees.Add(HrEmployee); IMSContext.SaveChanges(); return(Get(UserEntity, HrEmployee.Id)); }
public AdminEntity Create(UserEntity UserEntity, AdminEntity AdminEntity) { Admin Admin = AdminEntity.ToModel(); User User = new User(); User.Id = Admin.Id; User.Username = AdminEntity.Username; User.Password = "******"; IMSContext.Users.Add(User); IMSContext.Admins.Add(Admin); IMSContext.SaveChanges(); return(Get(UserEntity, Admin.Id)); }
public StudentEntity Create(UserEntity UserEntity, StudentEntity StudentEntity) { Student student = StudentEntity.ToModel(); User User = new User(); User.Id = student.Id; User.Username = StudentEntity.Username; User.Password = "******"; IMSContext.Users.Add(User); IMSContext.Students.Add(student); IMSContext.SaveChanges(); // return new StudentEntity(IMSContext.Students.Where(s => s.Id == student.Id).FirstOrDefault()); return(Get(UserEntity, student.Id)); }
public bool ChangePassword(Guid userId, PasswordEntity passwordEntity) { string oldPassword = GetHashString(passwordEntity.OldPassword); User User = IMSContext.Users.Where(u => u.Id.Equals(userId)).FirstOrDefault(); if (User == null) { return(false); } if (oldPassword.Equals(User.Password)) { passwordEntity.UserEntity.ToModel(User); User.Password = GetHashString(passwordEntity.UserEntity.Password); IMSContext.SaveChanges(); return(true); } return(false); }
public InternFollowEntity ChangeStatusFollow(UserEntity UserEntity, Guid InternNewsId) { var InternFollow = IMSContext.InternFollows.FirstOrDefault(If => If.InternNewsId == InternNewsId && If.StudentId == UserEntity.Id); if (InternFollow == null) { var InternFollowEntity = new InternFollowEntity { StudentId = UserEntity.Id, InternNewsId = InternNewsId, Status = 1 }; InternFollow = InternFollowEntity.ToModel(); IMSContext.InternFollows.Add(InternFollow); } else { InternFollow.Status = InternFollow.Status == 0 ? 1 : 0; } IMSContext.SaveChanges(); return(new InternFollowEntity(InternFollow)); }
public bool Delete(UserEntity userEntity, Guid internshipCourseId) { InternshipCourse internshipCourse = IMSContext.InternshipCourses.Where(s => s.Id == internshipCourseId).FirstOrDefault(); if (internshipCourse == null) { return(false); } Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); if (student == null) { return(false); } student.InternshipCourses.Remove(internshipCourse); IMSContext.InternshipCourses.Remove(internshipCourse); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity userEntity, Guid internNewsId) { Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); if (student == null) { return(false); } InternFollow internFollows = IMSContext.InternFollows.Where(s => s.InternNewsId == internNewsId && s.StudentId == student.Id).FirstOrDefault(); if (internFollows == null) { return(false); } student.InternFollows.Remove(internFollows); IMSContext.InternFollows.Remove(internFollows); IMSContext.SaveChanges(); return(true); }
public bool Delete(Guid internNewsId) { InternNews internNews = IMSContext.InternNews .Where(s => s.Id == internNewsId) .Include(i => i.InternFollows) .FirstOrDefault(); if (internNews == null) { return(false); } foreach (var item in internNews.InternFollows) { IMSContext.Remove(item); } IMSContext.SaveChanges(); IMSContext.Remove(internNews); IMSContext.SaveChanges(); return(true); }
public EmployeeService(IMSContext context, IMapper mapper) : base(context) { _context = context; _mapper = mapper; }