public async Task ApproveNewSubjectRequest_adds_new_subject_and_deletes_request() { var service = new AdminActivity(context); await service.ApproveNewSubjectRequest(3); Assert.AreEqual(true, context.Subject.Any(s => s.Title == "c#")); Assert.AreEqual(false, context.SubjectRequest.Any(s => s.Title == "c#")); }
public void AddSubject_throws_that_subject_exists() { var service = new AdminActivity(context); ArgumentException ex = Assert.Throws <ArgumentException>(() => service.AddSubject("")); Assert.That(ex.Message, Is.EqualTo("subject title cannot be empty.")); }
public void ApproveNewSubjectRequest_throws_that_subject_already_exists_despite_capital_letters_in_request() { var service = new AdminActivity(context); ArgumentException ex = Assert.ThrowsAsync <ArgumentException>(async() => await service.ApproveNewSubjectRequest(2)); Assert.That(ex.Message, Is.EqualTo("request cannot be approved: subject already exists.")); }
public void ApproveNewSubjectRequest_throws_that_subject_title_cannot_be_empty() { var service = new AdminActivity(context); ArgumentException ex = Assert.ThrowsAsync <ArgumentException>(async() => await service.ApproveNewSubjectRequest(5)); Assert.That(ex.Message, Is.EqualTo("request cannot be approved: subject title cannot be empty.")); }
public void SuspendUser_suspends_user() { var service = new AdminActivity(context); DateTime dateTime = DateTime.Now; service.SuspendUser(1, dateTime); Assert.AreEqual(1, context.Ban.Count()); }
public AdminActivityViewModel(AdminActivity comment) { FriendlyTime = comment.Time.ToFriendly().ToHtmlString(); // this is encoding when it shouldn't be Text = ""; Author = comment.User.UserName; GravatarUrl = (string.IsNullOrEmpty(comment.User.AvatarUrl)) ? comment.User.Email.ToGravatarUrl(40) : comment.User.AvatarUrl; OldStatus = comment.OldStatus; NewStatus = comment.NewStatus; OldStatusClass = StatusColorHelper.ColorClass(comment.OldStatus).ToHtmlString(); NewStatusClass = StatusColorHelper.ColorClass(comment.NewStatus).ToHtmlString(); }
public AdminActivityViewModel(AdminActivity comment) { FriendlyTime = comment.Time.ToFriendly().ToHtmlString(); // this is encoding when it shouldn't be Text = ""; Author = comment.User.UserName; GravatarUrl = (string.IsNullOrEmpty(comment.User.AvatarUrl)) ? comment.User.Email.ToGravatarUrl(40) : comment.User.AvatarUrl; OldStatus = comment.OldStatus; NewStatus = comment.NewStatus; OldStatusClass = StatusColorHelper.ColorClass(comment.OldStatus).ToHtmlString(); NewStatusClass = StatusColorHelper.ColorClass(comment.NewStatus).ToHtmlString(); }
public AdminActivity CreateActivity(AdminActivity adminActivity) { try { context.AdminActivity.Add(adminActivity); context.SaveChanges(); return(adminActivity); } catch (Exception ex) { adminActivity.ErrorMessage = ex.Message; return(adminActivity); } }
public static void Create(string category, string description, int adminId) { AdminActivity adminActivity = new AdminActivity() { Administrators_Id = adminId, Category = category, Description = description, Ip_Address = IpAddress.GetLocalIPAddress(), Activity_CreatedDate = DateTime.Now, Activity_UpdatedDate = DateTime.Now }; bAdministrator.Create(adminActivity); }
private void ReInitializeReportViewer() { //if (prevValue == newValue) // return; AdminActivity.Clear(); AdminActivity.Dispose(); this.Controls.Remove(this.AdminActivity); GC.Collect(); this.AdminActivity = new Microsoft.Reporting.WinForms.ReportViewer(); this.AdminActivity.Dock = System.Windows.Forms.DockStyle.Fill; reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource(); reportDataSource3 = new Microsoft.Reporting.WinForms.ReportDataSource(); //reportDataSource4 = new Microsoft.Reporting.WinForms.ReportDataSource(); //reportDataSource3.Name = "Taxi_Model_Vu_BookingBase"; //reportDataSource3.Value = this.Vu_BookingBaseBindingSource; //reportDataSource4.Name = "Taxi_AppMain_Classes_ClsLogo"; //reportDataSource4.Value = this.ClsLogoBindingSource; reportDataSource2.Name = "Taxi_Model_stp_ActivityLogResult"; reportDataSource2.Value = this.stp_ActivityLogResultBindingSource; //reportDataSource3.Name = "Taxi_AppMain_Classes_ClsLogo"; //reportDataSource3.Value = this.ClsLogoBindingSource; this.AdminActivity.LocalReport.DataSources.Add(reportDataSource2); this.AdminActivity.LocalReport.DataSources.Add(reportDataSource3); this.AdminActivity.LocalReport.ReportEmbeddedResource = "Taxi_AppMain.ReportDesigns.rptActivityLog.rdlc"; this.AdminActivity.Location = new System.Drawing.Point(0, 137); this.AdminActivity.Name = "AdminActivity"; this.AdminActivity.Size = new System.Drawing.Size(1040, 675); this.AdminActivity.TabIndex = 116; this.Controls.Add(this.AdminActivity); AdminActivity.BringToFront(); //prevValue = newValue; }
public static IEnumerable<string> UserCanAffect(IEnumerable<string> userRoles, IEnumerable<string> rolesToFilter, AdminActivity activity) { var userRules = Rules.Where(ru => ru.Activity == activity && userRoles.Any(ro => ro == ru.RoleOfActingUser)); var result = userRules.SelectMany(r => r.AllowedTargetRoles).Distinct(); return result; }
public AdminActivity Create(AdminActivity adminActivity) { return(_administrator.CreateActivity(adminActivity)); }
public static AdminActivity Create(AdminActivity adminActivity) { dAdministrator _dAdministrator = new dAdministrator(); return(_dAdministrator.CreateActivity(adminActivity)); }
public ActionResult AddSession(int id, string session, HttpPostedFileBase file) { if (!HasSession()) { return(RedirectToAction("Index", "Home")); } Admin admin = HttpContext.Session[Variables.AdminSession] as Admin; if (session != null && file != null) { string fileName = "", targetFileName = session.Trim().Replace("-", "_") + "_students"; string content = ""; if ((file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { fileName = Path.GetFileName(file.FileName); if (fileName.ToLower().Contains(".xls") || fileName.ToLower().Contains(".xlsx")) { //read excel data List <StudentInfo> stuInfo = new ExcelReader().readStuInfoFromExcel(file); //insret student informations into StudentInfo table if (stuInfo != null) { foreach (StudentInfo info in stuInfo) { content += info.StudentId + ","; db.StudentInfo.Add(info); db.SaveChanges(); ViewBag.Message = "Session Created Successfully!"; } //insert new session into AllSession table AllSession a = new AllSession(); a.Session = session; a.Content = content; db.AllSession.Add(a); db.SaveChanges(); //add this activity into Activity table try { //targetFileName += "_" + DateTime.Now.ToString().Replace("/", "_").Replace(" ", "_").Replace(":", "_") + ".xlsx"; targetFileName += ".xlsx"; string path = Path.Combine(Server.MapPath("~/App_Data/Stu_Info/"), targetFileName); file.SaveAs(path); ViewBag.FileInfo = targetFileName + " uploaded successfully!"; AdminActivity activity = new AdminActivity(); activity.Name = admin.Username; activity.UserId = Convert.ToString(admin.id); activity.Time = DateTime.Now.ToString(); activity.Message = "New Session created: " + session; activity.Content = content; activity.FilePath = path; db.AdminActivity.Add(activity); db.SaveChanges(); } catch (Exception ex) { ViewBag.Error = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Error = "ERROR:" + " Excel formet is Missmatche..!"; } } else { //format not supported ViewBag.Message = "File formate not supported. Only .xls or .xlsx is required."; } } else { //empty file ViewBag.Message = "Empty File."; } } else { ViewBag.Message = "Required field(s) missing."; } return(View(admin)); }
public static AccessRule Create(string roleOfActingUser, AdminActivity activity, IEnumerable<string> allowedTargetRoles) { return new AccessRule { RoleOfActingUser = roleOfActingUser, Activity = activity, AllowedTargetRoles = allowedTargetRoles }; }