public ActionResult Create() { ViolationViewModel vm = new ViolationViewModel(); vm.PopulateDropDowns(this.eventTasks.GetViolations()); return(View(vm)); }
public ActionResult Create(ViolationViewModel vm) { if (ModelState.IsValid) { // TODO would be nice to have a unique constraint annotation we could use on the view model if (this.eventTasks.GetViolation(vm.Name) == null) { Violation violation = new Violation(); violation.Name = vm.Name; violation.Keywords = vm.Keywords; violation.Description = vm.Description; violation.ConditionalityInterest = vm.ConditionalityInterest; if (vm.ParentViolationID.HasValue) { violation.ParentViolation = this.eventTasks.GetViolation(vm.ParentViolationID.Value); } violation = this.eventTasks.SaveViolation(violation); return(RedirectToAction("Details", new { id = violation.Id })); } else { ViewData.ModelState.AddModelError("Name", "A violation with that name already exists."); } } return(Create()); }
public ActionResult Edit(int id) { Violation v = this.eventTasks.GetViolation(id); if (v != null) { ViolationViewModel vm = new ViolationViewModel(); vm.Id = v.Id; vm.Name = v.Name; vm.Keywords = v.Keywords; vm.Description = v.Description; vm.ConditionalityInterest = v.ConditionalityInterest; if (v.ParentViolation != null) { vm.ParentViolationID = v.ParentViolation.Id; } IList <Violation> parentCandidates = this.eventTasks.GetViolations(); parentCandidates.Remove(v); vm.PopulateDropDowns(parentCandidates); return(View(vm)); } else { return(new HttpNotFoundResult()); } }
public ActionResult Edit(ViolationViewModel vm) { if (ModelState.IsValid) { Violation existingViolation = this.eventTasks.GetViolation(vm.Name); if (existingViolation == null || (existingViolation != null && existingViolation.Id == vm.Id)) { Violation violation = this.eventTasks.GetViolation(vm.Id); violation.Name = vm.Name; violation.Keywords = vm.Keywords; violation.Description = vm.Description; violation.ConditionalityInterest = vm.ConditionalityInterest; if (vm.ParentViolationID.HasValue) { violation.ParentViolation = this.eventTasks.GetViolation(vm.ParentViolationID.Value); } else { violation.ParentViolation = null; } violation = this.eventTasks.SaveViolation(violation); return(RedirectToAction("Details", new { id = vm.Id })); } else { ViewData.ModelState.AddModelError("Name", "A violation with that name already exists."); } } return(Edit(vm.Id)); }
public async Task <IActionResult> UpdateViolation(ViolationViewModel violation) { var mapViolation = _mapper.Map <Violation>(violation); await _violationService.UpdateAsync(mapViolation); return(Ok()); }
public ActionResult Contact() { ViewBag.Message = "Contact ODU's Spring 2017 CS411W Red Team"; var usr = User.Identity.GetUserId(); var vm = new ViolationViewModel(); var db = new CPPdatabaseEntities(); var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db); var sessions = db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId) .Select(session => session.CallSenderId) .ToList(); sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId)); foreach (var partnerId in sessions) { //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single()); vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO() { Email = x.AspNetUser.Email, Id = x.AspNetUser.Id, UserName = x.AspNetUser.UserName }).Single()); } var withoutDupes = vm.List.GroupBy(user => user.Email).Select(group => group.First()); vm.List = withoutDupes.ToList(); ViewData["ViolationList"] = vm.List; //ViewData["userIsAdmin"] = db.CppUsers.Where(x => x.AspNetUserId == usr).Select(x => x.PermissionLevel).Single() == 1; ViewBag.ListItems = vm.List; ViewData["userIsAdmin"] = db.CppUsers.Single(x => x.Id == thisCppUserId).PermissionLevel == 1; return(View()); }
// GET: Violation public ActionResult Index() { var vm = new ViolationViewModel(); var db = new CPPdatabaseEntities(); var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db); var sessions = db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId) .Select(session => session.CallSenderId) .ToList(); sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId)); foreach (var partnerId in sessions) { //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single()); vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO() { Email = x.AspNetUser.Email, Id = x.AspNetUser.Id, UserName = x.AspNetUser.UserName }).Single()); } return(View(vm)); }
public async Task <IActionResult> Create() { var model = new ViolationViewModel(); await PopulateDropDownCategory(model); return(View(model)); }
public Task <IActionResult> CreateViolation(ViolationViewModel inspector) { if (!ModelState.IsValid) { return(CreateViolation(inspector)); } return(CreateViolationInternal(inspector)); }
private async Task PopulateDropDownCategory(ViolationViewModel model) { var Categories = await CommonContext.CommonViolationCategories.Select(m => new SelectListItem { Text = m.Name + " (" + m.Type.Name + " )", Value = m.Id.ToString(), }).ToListAsync(); model.Categories.AddRange(Categories); }
public ActionResult SaveViolation(ViolationViewModel model) { using (MTCDbContext db = new MTCDbContext()) { Violation Violation = null; bool isNew = false; if (model.Id > 0) { Violation = db.Violations.Find(model.Id); } else { Violation = new Violation(); Violation.CreatedOn = DateTime.Now; Violation.CreatedBy = HttpContext.User.Identity.Name; isNew = true; } Violation.ViolationTypeId = model.ViolationTypeId; Violation.ContractorId = model.ContractorId; Violation.DateTimeOfViolation = model.DateTimeOfViolation; Violation.BeatId = model.BeatId; Violation.DriverId = model.DriverId; Violation.FleetVehicleId = model.FleetVehicleId; Violation.CallSign = model.CallSign; Violation.OffenseNumber = model.OffenseNumber; Violation.ViolationStatusTypeId = model.ViolationStatusTypeId; Violation.DeductionAmount = model.DeductionAmount; Violation.Notes = model.Notes; Violation.PenaltyForDriver = model.PenaltyForDriver; Violation.LengthOfViolation = "0"; Violation.ModifiedOn = DateTime.Now; Violation.ModifiedBy = HttpContext.User.Identity.Name; if (isNew) { db.Violations.Add(Violation); } db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } }
public static ViolationViewModel ConverToViewModel(this bx_violationlog detail) { var vm = new ViolationViewModel() { AcceptagencyCode = detail.acceptagencycode ?? string.Empty, Coeff = detail.coeff ?? 0, LossAction = detail.lossAction ?? string.Empty, LossActionDesc = detail.lossActionDesc ?? string.Empty, LossTime = detail.lossTime ?? string.Empty, PeccancyId = detail.peccancyid ?? string.Empty, ProcessingStatus = detail.processingStatus ?? string.Empty, SanctionDate = detail.sanctionDate ?? string.Empty, ViolationRecordTypeName = detail.violationRecordTypeName ?? string.Empty }; return(vm); }
public async Task <IActionResult> Edit(ViolationViewModel model) { if (ModelState.IsValid) { var Violation = new CommonViolation() { Name = model.Name.Trim(), Description = model.Description?.Trim(), Disabled = model.Disabled, HelpUrl = model.HelpUrl, Actions = model.Actions, CategoryId = model.CategoryId, Category = await CommonContext.CommonViolationCategories.SingleAsync(m => m.Id == model.CategoryId), Id = model.Id, RequiredFields = model.Fields, ReminderMinutes = model.ReminderMinutes, ReminderMessage = model.ReminderMessage }; var NameAlreadyExists = await CommonContext.CommonViolations.AnyAsync( q => q.Name.ToLower() == model.Name.Trim().ToLower() && q.CategoryId == model.CategoryId && q.Id != model.Id ); if (NameAlreadyExists) { // This isn't a security risk because we've verified the Name already exists ModelState.AddModelError(string.Empty, "Violation Name with this Violation Category already exists."); } else { var result = await _violationSvc.UpdateViolation(Violation, User.GetLoggedInUserId().Value); //Purge common accounts cache await _cache.RemoveAsync(WebCacheKey.CommonViolations); return(RedirectToAction("Index")); } } await PopulateDropDownCategory(model); return(View(model)); }
public async Task <IActionResult> Edit(Guid Id) { var model = new ViolationViewModel(); //get data from database by id var violationDetails = await CommonContext.CommonViolations.SingleOrDefaultAsync(violation => violation.Id == Id); model.Name = violationDetails.Name; model.Description = violationDetails.Description; model.Disabled = violationDetails.Disabled; model.Id = violationDetails.Id; model.CategoryId = violationDetails.CategoryId; model.HelpUrl = violationDetails.HelpUrl; model.Actions = violationDetails.Actions; model.Fields = violationDetails.RequiredFields; model.ReminderMessage = violationDetails.ReminderMessage; model.ReminderMinutes = violationDetails.ReminderMinutes; await PopulateDropDownCategory(model); return(View(model)); }
public IActionResult AddViolationForUser([FromForm] ViolationViewModel violation) { _policeService.AddViolationForUser(_mapper.Map <Violations>(violation)); return(Ok()); }
public IActionResult AddViolationForUser([FromForm] ViolationViewModel violation) { long violationId = _policePresentation.AddViolationForUser(_mapper.Map <Violations>(violation)); return(Ok(violationId)); }
private async Task <IActionResult> CreateViolationInternal(ViolationViewModel violation) { await _client.PostAsync("violations", violation); return(RedirectToAction(nameof(ShowViolations))); }
public async Task <IActionResult> UpdateViolation(ViolationViewModel violation) { await _client.PutAsync("violations", violation); return(RedirectToAction(nameof(ShowViolations))); }