public ResultSvc <InstructorRole> ChangeOrder(InstructorRole instructorRole, bool up) { var result = new ResultSvc <InstructorRole>(instructorRole); try { if ((instructorRole.Order == 1 && up) || (instructorRole.Order == InstructorRoles.Items.Select(x => x.Order).DefaultIfEmpty(1).Max() && !up)) { result.Errors.Add("Nelze změnit pořadí! Pořadí je již buď nejmenší nebo největší možné."); } else { var iRole = InstructorRoles.Items.FirstOrDefault(x => x.Order == (up ? instructorRole.Order - 1 : instructorRole.Order + 1)); iRole.Order = up ? iRole.Order + 1 : iRole.Order - 1; iRole.UserUpdatedId = Context.HttpContext.User.GetUserId(); instructorRole.Order = up ? instructorRole.Order - 1 : instructorRole.Order + 1; instructorRole.UserUpdatedId = Context.HttpContext.User.GetUserId(); InstructorRoles.Update(iRole); InstructorRoles.Update(instructorRole); } } catch (Exception e) { Logger.LogError(e.Message); } return(result); }
public IActionResult Edit(InstructorRole model) { if (ModelState.IsValid) { model.UserUpdatedId = User.GetUserId(); Svc.InstructorRoles.Update(model); Svc.Commit(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Create(InstructorRole model) { if (ModelState.IsValid) { Svc.CreateInstructorRole(model); Svc.Commit(); return(RedirectToAction("Index")); } return(View(model)); }
public ResultSvc <InstructorRole> DeleteInstructorRole(InstructorRole instructorRole) { var result = new ResultSvc <InstructorRole>(instructorRole); try { foreach (var ir in InstructorRoles.Items.Where(x => x.Order > instructorRole.Order)) { ir.Order--; InstructorRoles.Update(ir); } instructorRole.UserDeletedId = Context.HttpContext.User.GetUserId(); InstructorRoles.Delete(instructorRole); } catch (Exception e) { Logger.LogError(e.Message); } return(result); }
public ResultSvc <InstructorRole> CreateInstructorRole(InstructorRole role) { var result = new ResultSvc <InstructorRole>(role); try { if (!InstructorRoles.Items.Any(x => x.Name == role.Name.Trim())) { role.Name = role.Name?.Trim(); role.Order = InstructorRoles.Items.Select(x => x.Order).DefaultIfEmpty(0).Max() + 1; role.UserCreatedId = Context.HttpContext.User.GetUserId(); InstructorRoles.Add(role); } else { result.Errors.Add("Role s tímto názvem již existuje!"); } } catch (Exception e) { Logger.LogError(e.Message); } return(result); }