private void InitUserAdmin() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = new User(); user.Username = "******"; user.FullName = "Super Admin"; user.Email = "*****@*****.**"; user.Password = "******"; /*var password = "******"; * password.GeneratePassword(out string saltKey, out string hashPass); * * user.Password = hashPass;*/ user.Gender = UserEnums.UserGender.Nam; var users = new[] { user }; userRepository.GetDbContext().Users.AddIfNotExist(x => x.Email, users ); userRepository.GetDbContext().SaveChanges(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (ClassificationOfScientificWorkId == Guid.Empty) { yield return(new ValidationResult("ClassificationOfScientificWork is required!", new string[] { "ClassificationOfScientificWorkId" })); } var levelRepository = IoCHelper.GetInstance <IRepository <ClassificationOfScientificWork> >(); var level = levelRepository.GetAll().FirstOrDefault(x => x.Id == ClassificationOfScientificWorkId); if (level == null) { yield return(new ValidationResult("ClassificationOfScientificWork is not found!", new string[] { "ClassificationOfScientificWorkId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); if (LecturerIds.Count <= 0) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerIds" })); } foreach (var lecturerId in LecturerIds) { var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == lecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!", new string[] { "lecturerId" })); } } }
// validate public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var majorRepository = IoCHelper.GetInstance <IRepository <Major> >(); var major = majorRepository.GetAll().FirstOrDefault(x => x.Id == MajorId); if (major == null) { yield return(new ValidationResult("Major is not found!", new string[] { "MajorId" })); } var standardOfCertificateRepository = IoCHelper.GetInstance <IRepository <StandardOfCertificate> >(); var standardOfCertificate = standardOfCertificateRepository.GetAll().FirstOrDefault(x => x.Id == StandardOfCertificateId); if (standardOfCertificate == null) { yield return(new ValidationResult("StandardOfCertificate is not found!", new string[] { "StandardOfCertificateId" })); } //if (string.IsNullOrWhiteSpace(Name)) //{ // yield return new ValidationResult("SpecialtyName can't be null or WhiteSpace!", new string[] { "SpecialtyName" }); //} //var specialtyRepository = IoCHelper.GetInstance<IRepository<Specialty>>(); //var specialty = specialtyRepository.GetAll().FirstOrDefault(x => x.Name == Name && x.Id == Id); //if (specialty != null) //{ // yield return new ValidationResult("SpecialtyName already exists!", new string[] { "SpecialtyName" }); //} }
public StudentViewModel(Student student) : this() { if (student != null) { Id = student.Id; Username = student.Username; FirstName = student.FirstName; LastName = student.LastName; Email = student.Email; Gender = student.Gender; DateOfBirth = student.DateOfBirth; ExtracurricularPoint = 0; CertificateStatus = new CertificateStatusViewModel(student.CertificateStatus); var extracurricularRepository = IoCHelper.GetInstance <IRepository <Extracurricular> >(); var extracurricularActivityRepository = IoCHelper.GetInstance <IRepository <ExtracurricularActivity> >(); var extracurricularActivityIdArray = extracurricularRepository.GetAll() .Where(x => x.StudentId == Id).Select(x => x.ExtracurricularActivityId).ToArray(); Class = new ClassViewModel(student.Class); //ClassId = student.ClassId; //SpecialtyId = student.SpecialtyId; Specialty = new SpecialtyViewModel(student.Specialty); foreach (var extracurricularActivityId in extracurricularActivityIdArray) { ExtracurricularPoint += extracurricularActivityRepository.GetAll().FirstOrDefault(x => x.Id == extracurricularActivityId).Point; } // Lấy điểm của từng //ExtracurricularPoint = student //Roles = user.UserInRoles != null ? user.UserInRoles.Select(y => new RoleViewModel(y.Role)).ToArray() : null; } }
public JwtPayload ValidateToken(string token) { var appSetting = IoCHelper.GetInstance <IOptions <AppSettings> >(); try { if (string.IsNullOrEmpty(token)) { return(null); } var json = new JwtBuilder() .WithSecret(appSetting.Value.Secret) .MustVerifySignature() .Decode(token); var jwtJsonDecode = JsonConvert.DeserializeObject <JwtJsonDecode>(json); if (jwtJsonDecode == null || jwtJsonDecode.JwtPayload == null) { return(null); } else { return(jwtJsonDecode.JwtPayload); } } catch (TokenExpiredException) { return(null); } catch (SignatureVerificationException) { return(null); } }
public StudentProfileViewModel(Student student) : this() { if (student != null) { Id = student.Id; FirstName = student.FirstName; LastName = student.LastName; Photo = student.Photo; DateOfBirth = student.DateOfBirth; Email = student.Email; Gender = student.Gender; ExtracurricularPoint = 0; var extracurricularRepository = IoCHelper.GetInstance <IRepository <Extracurricular> >(); var extracurricularActivityRepository = IoCHelper.GetInstance <IRepository <ExtracurricularActivity> >(); var extracurricularActivityIdArray = extracurricularRepository.GetAll() .Where(x => x.Id == Id).Select(x => x.ExtracurricularActivityId).ToArray(); foreach (var extracurricularActivityId in extracurricularActivityIdArray) { ExtracurricularPoint += extracurricularActivityRepository.GetAll().FirstOrDefault(x => x.Id == extracurricularActivityId).Point; } } }
private void InitDataRole() { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); var roles = new[] { new Role { Id = RoleConstants.SuperAdminId, Name = "Super Admin" }, new Role { Id = RoleConstants.AdminId, Name = "ADMIN" }, new Role { Id = RoleConstants.ShipperId, Name = "Shipper" }, new Role { Id = RoleConstants.UserId, Name = "USER" } }; roleRepository.GetDbContext().Roles.AddIfNotExist(x => x.Name, roles); roleRepository.GetDbContext().SaveChanges(); }
private void InitDataRole() { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); var roles = new[] { new Role { Id = RoleConstants.SuperAdminId, Name = "Super Admin" }, new Role { Id = RoleConstants.ArticleManagerId, Name = "Article Manager" }, new Role { Id = RoleConstants.ExtracurricularManagerId, Name = "Extracurricular Manager" }, new Role { Id = RoleConstants.StructureManagerId, Name = "Structure Manager" }, new Role { Id = RoleConstants.UserManagerId, Name = "User Manager" }, new Role { Id = RoleConstants.StudentManagerId, Name = "Student Manager" } }; roleRepository.GetDbContext().Roles.AddIfNotExist(x => x.Name, roles); roleRepository.GetDbContext().SaveChanges(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (BookCategoryId == Guid.Empty) { yield return(new ValidationResult("BookCategory is required!", new string[] { "BookCategoryId" })); } var bookCategoryRepository = IoCHelper.GetInstance <IRepository <BookCategory> >(); var bookCategory = bookCategoryRepository.GetAll().FirstOrDefault(x => x.Id == BookCategoryId); if (bookCategory == null) { yield return(new ValidationResult("BookCategory is not found!", new string[] { "BookCategoryId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); if (LecturerIds.Count <= 0) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerIds" })); } foreach (var lecturerId in LecturerIds) { var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == lecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!", new string[] { "lecturerId" })); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); if (RoleIds.Count <= 0) { yield return(new ValidationResult("Role is required!", new string[] { "RoleIds" })); } foreach (var roleId in RoleIds) { var role = roleRepository.GetAll().FirstOrDefault(x => x.Id == roleId); if (role == null) { yield return(new ValidationResult("Role is not found!", new string[] { "RoleId" })); } } var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = userRepository.GetAll().FirstOrDefault(x => x.Email == Email); if (user != null) { yield return(new ValidationResult("Email already exists!", new string[] { "Email" })); } user = userRepository.GetAll().FirstOrDefault(x => x.Username == Username); if (user != null) { yield return(new ValidationResult("Username already exists!", new string[] { "Username" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (LevelStudyGuideId == Guid.Empty) { yield return(new ValidationResult("LevelStudyGuideId is required!", new string[] { "LevelId" })); } var levelRepository = IoCHelper.GetInstance <IRepository <LevelStudyGuide> >(); var level = levelRepository.GetAll().FirstOrDefault(x => x.Id == LevelStudyGuideId); if (level == null) { yield return(new ValidationResult("LevelStudyGuide is not found!", new string[] { "LevelStudyGuideId" })); } if (LecturerId == Guid.Empty) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == LecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!")); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); if (RoleIds.Count <= 0) { yield return(new ValidationResult("Role is required!", new string[] { "RoleIds" })); } foreach (var roleId in RoleIds) { var role = roleRepository.GetAll().FirstOrDefault(x => x.Id == roleId); if (role == null) { yield return(new ValidationResult("Role is not found!", new string[] { "RoleId" })); } } var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = userRepository.GetAll().FirstOrDefault(x => x.FullName == FullName); if (FullName.Length <= 2) { yield return(new ValidationResult("Invalid FullName!", new string[] { "FullName" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var studentRepository = IoCHelper.GetInstance <IRepository <Student> >(); var student = studentRepository.GetAll().FirstOrDefault(x => x.Id == StudentId); if (student == null) { yield return(new ValidationResult("Student is not found!", new string[] { "StudentId" })); } }
public async Task <IActionResult> GetCertificateStatus() { var studentRepository = IoCHelper.GetInstance <IRepository <Student> >(); var SelfCertificateStatusId = studentRepository.GetAll() .FirstOrDefault(x => x.Id == CurrentUserId).CertificateStatusId; var certificateStatus = await _certificateStatusService.GetCertificateStatusBySelfIdAsync(SelfCertificateStatusId); return(Ok(certificateStatus)); }
// validate public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var standardOfCertificateRepository = IoCHelper.GetInstance <IRepository <ArticleCategory> >(); var standardOfCertificate = standardOfCertificateRepository.GetAll().FirstOrDefault(x => x.Id == ArticleCategoryId); if (standardOfCertificate == null) { yield return(new ValidationResult("ArticleCategory is not found!", new string[] { "ArticleCategoryId" })); } }
public async Task <IActionResult> GetStandardOfCertificateBySelfId() { var studentRepository = IoCHelper.GetInstance <IRepository <Student> >(); var specialtyId = studentRepository.GetAll().FirstOrDefault(x => x.Id == CurrentUserId).SpecialtyId; var specialtyRepository = IoCHelper.GetInstance <IRepository <Specialty> >(); var selfStandardOfCertificateId = specialtyRepository.GetAll() .FirstOrDefault(x => x.Id == specialtyId).StandardOfCertificateId; var standardOfCertificate = await _standardOfCertificateService.GetStandardOfCertificateBySelfIdAsync(selfStandardOfCertificateId); return(Ok(standardOfCertificate)); }
public string GenerateToken(JwtPayload payload) { var appSetting = IoCHelper.GetInstance <IOptions <AppSettings> >(); var token = new JwtBuilder() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSecret(appSetting.Value.Secret) .AddClaim("Expired", DateTimeOffset.UtcNow.AddMonths(1).ToUnixTimeSeconds()) .AddClaim("JwtPayload", payload) .Build(); return(token); }
private void InitSizes() { var sizeRepository = IoCHelper.GetInstance <IRepository <Size> >(); var sizes = new[] { new Size(SizeConstants.Medium.Id, SizeConstants.Medium.Name), new Size(SizeConstants.Large.Id, SizeConstants.Large.Name) }; sizeRepository.GetDbContext().Sizes.AddIfNotExist(x => x.Name, sizes); sizeRepository.GetDbContext().SaveChanges(); }
public static bool SendMessage(string text, string to) { var appSetting = IoCHelper.GetInstance <IOptions <AppSettings> >(); TwilioClient.Init(appSetting.Value.AccountSid, appSetting.Value.AuthToken); var message = MessageResource.Create( body: text, from: new Twilio.Types.PhoneNumber("+12015716421"), to: new Twilio.Types.PhoneNumber(to) ); return(true); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var categoryRepository = IoCHelper.GetInstance <IRepository <Category> >(); if (CategoryIds == null || CategoryIds.Length == 0) { yield return(new ValidationResult("Category not be null", new string[] { "CategoryIds" })); } if (!CategoryIds.All(x => categoryRepository.GetAll().Select(y => y.Id).Contains(x))) { yield return(new ValidationResult("Invalid Category", new string[] { "CategoryIds" })); } }
private void InitCategories() { var categoryRepository = IoCHelper.GetInstance <IRepository <Category> >(); var categories = new[] { new Category(CategoryConstants.FirstCategoryId, CategoryConstants.FirstCategoryName, ""), new Category(CategoryConstants.SecondCategoryId, CategoryConstants.SecondCategoryName, ""), new Category(CategoryConstants.ThirdCategoryId, CategoryConstants.ThirdCategoryName, "") }; categoryRepository.GetDbContext().Categories.AddIfNotExist(x => x.Name, categories); categoryRepository.GetDbContext().SaveChanges(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); if (UserIds == null || UserIds.Length == 0) { yield return(new ValidationResult("User not be null", new string[] { "UserIds" })); } if (!UserIds.All(x => userRepository.GetAll().Select(y => y.Id).Contains(x))) { yield return(new ValidationResult("Invalid User", new string[] { "UserIds" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var categoryRepository = IoCHelper.GetInstance <IRepository <Category> >(); if (CategoryId == null) { yield return(new ValidationResult(ProductMessagesConstants.CATEGORY_NOT_FOUND, new string[] { "CategoryId" })); } var category = categoryRepository.GetAll().FirstOrDefault(x => x.Id == CategoryId); if (category == null) { yield return(new ValidationResult(ProductMessagesConstants.CATEGORY_NOT_FOUND, new string[] { "CategoryId" })); } }
private void InitUsers() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = new User(); user.Email = "*****@*****.**"; var password = "******"; password.GeneratePassword(out string saltKey, out string hashPass); user.Name = "Trần Văn Tài"; user.Address = "101B Lê Hữu Trác, Sơn Trà, Đà Nẵng"; user.DateOfBirth = new DateTime(1999, 03, 16); user.Gender = UserEnums.Gender.Male; user.PhoneNumber = "0915981110"; user.Password = hashPass; user.PasswordSalt = saltKey; user.RecordActive = true; user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = user.Id, RoleId = RoleConstants.CustomerId, RecordActive = true } }; user.Orders = new List <Order>() { InitOrder(user.Id) }; var users = new[] { user }; userRepository.GetDbContext().Users.AddIfNotExist(x => x.Email, users); userRepository.GetDbContext().SaveChanges(); }
private void InitUserAdmin() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); if (userRepository.GetAll().Count() > 0) { return;// It's already init } var user = new User(); user.Username = "******"; user.FullName = "Super Admin"; user.Email = "*****@*****.**"; var password = "******"; password.GeneratePassword(out string saltKey, out string hashPass); user.Password = hashPass; user.PasswordSalt = saltKey; user.Gender = UserEnums.Gender.Male; user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = UserConstants.SuperAdminUserId, RoleId = RoleConstants.SuperAdminId } }; var users = new[] { user }; userRepository.GetDbContext().Users.AddIfNotExist(x => x.FullName, users); userRepository.GetDbContext().SaveChanges(); }
private void InitUserAdmin() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); if (userRepository.GetAll().Count() > 0) { return;// It's already init } var user = new User(); user.Email = "*****@*****.**"; var password = "******"; password.GeneratePassword(out string saltKey, out string hashPass); user.Name = "Đặng Thành Tài"; user.Address = "Thái Thủy, Lệ Thủy, Quảng Bình"; user.DateOfBirth = new DateTime(1999, 01, 29); user.Gender = UserEnums.Gender.Male; user.PhoneNumber = "0915981110"; user.Password = hashPass; user.PasswordSalt = saltKey; user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = UserConstants.SuperAdminUserId, RoleId = RoleConstants.SuperAdminId } }; var users = new[] { user }; userRepository.GetDbContext().Users.AddIfNotExist(x => x.Email, users); userRepository.GetDbContext().SaveChanges(); }
public async Task <IActionResult> UpdateComment(Guid shopId, Guid commentId, [FromBody] CommentManageModel commentManageModel) { var commentRepository = IoCHelper.GetInstance <IRepository <Comment> >(); var comment = commentRepository.GetAll().Where(x => x.Id == commentId && x.UserId == CurrentUserId).FirstOrDefault(); if (comment == null) { return(StatusCode(403, new { Message = "Forbidden" })); } var responseModel = await _commentService.UpdateCommentAsync(CurrentUserId, shopId, commentId, commentManageModel); if (responseModel.StatusCode == System.Net.HttpStatusCode.OK) { return(Ok(responseModel.Message)); } else { return(BadRequest(new { Message = responseModel.Message })); } }
private void InitUser() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var userDevs = new User[] { new User() { Email = "*****@*****.**", Name = "Quang Nguyen", }, new User() { Email = "*****@*****.**", Name = "Thanh Nguyen", }, new User() { Email = "*****@*****.**", Name = "Phuong Trinh", } }; var userHRs = new User[] { new User() { Email = "*****@*****.**", Name = "Quan Le", }, new User() { Email = "*****@*****.**", Name = "Liu Huynh", } }; var userHRMs = new User[] { new User() { Email = "*****@*****.**", Name = "Thoai Tran", } }; var userBODs = new User[] { new User() { Email = "*****@*****.**", Name = "Trinh Vo", } }; foreach (var user in userDevs) { user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = user.Id, RoleId = RoleConstants.UserId } }; } foreach (var user in userHRs) { user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = user.Id, RoleId = RoleConstants.ShipperId } }; } foreach (var user in userHRMs) { user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = user.Id, RoleId = RoleConstants.ShipperId } }; } foreach (var user in userBODs) { user.UserInRoles = new List <UserInRole>() { new UserInRole() { UserId = user.Id, RoleId = RoleConstants.AdminId } }; } var users = userDevs.Concat(userHRs).Concat(userHRMs).Concat(userBODs).ToArray(); foreach (var user in users) { user.Mobile = "01234567890"; var password = "******"; password.GeneratePassword(out string saltKey, out string hashPass); user.Password = hashPass; user.PasswordSalt = saltKey; } userRepository.GetDbContext().Users.AddIfNotExist(x => x.Email, users); userRepository.GetDbContext().SaveChanges(); }
private void InitProducts() { var productRepository = IoCHelper.GetInstance <IRepository <Product> >(); var products = new[] { new Product() { Name = "Trà Đào Hạt Chia", Image = "http://localhost:6600/api/media/ProductImage/4a92b1fd-6a2d-47bb-be53-bc71e0876f87.jpg", CategoryId = CategoryConstants.SecondCategoryId, ProductSizes = new List <ProductSize>() { InitProductSizes(new Guid(), SizeConstants.Medium.Id, 20000), InitProductSizes(new Guid(), SizeConstants.Large.Id, 30000) }, RecordActive = true }, new Product() { Name = "Trà Đào Đường Đen", Image = "http://localhost:6600/api/media/ProductImage/201862816548-tra-sua-toco.jpg", CategoryId = CategoryConstants.SecondCategoryId, ProductSizes = new List <ProductSize>() { InitProductSizes(new Guid(), SizeConstants.Medium.Id, 25000), InitProductSizes(new Guid(), SizeConstants.Large.Id, 35000) }, RecordActive = true }, new Product() { Name = "Trà Sữa Sôcôla", Image = "http://localhost:6600/api/media/ProductImage/2018416153535-hongtravietquat.jpg", CategoryId = CategoryConstants.FirstCategoryId, ProductSizes = new List <ProductSize>() { InitProductSizes(new Guid(), SizeConstants.Medium.Id, 30000), InitProductSizes(new Guid(), SizeConstants.Large.Id, 38000) }, RecordActive = true }, new Product() { Name = "Trà Sữa Bạc Hà", Image = "http://localhost:6600/api/media/ProductImage/2018628165317-tra-sua-panda-new-.jpg", CategoryId = CategoryConstants.FirstCategoryId, ProductSizes = new List <ProductSize>() { InitProductSizes(new Guid(), SizeConstants.Medium.Id, 20000), InitProductSizes(new Guid(), SizeConstants.Large.Id, 28000) }, RecordActive = true }, new Product() { Name = "Trà Sữa Hương Dâu", Image = "http://localhost:6600/api/media/ProductImage/2018629104230-o-long-kem-pho-mai.jpg", CategoryId = CategoryConstants.FirstCategoryId, ProductSizes = new List <ProductSize>() { InitProductSizes(new Guid(), SizeConstants.Medium.Id, 24000), InitProductSizes(new Guid(), SizeConstants.Large.Id, 30000) }, RecordActive = true } }; productRepository.GetDbContext().Products.AddIfNotExist(x => x.Name, products); productRepository.GetDbContext().SaveChanges(); }