public IActionResult CreateAssignment(int courseId) { var vm = new AssignmentVM { CourseId = courseId }; return(View(vm)); }
public ActionResult CreateAssignment() { AssignmentVM assignmment = new AssignmentVM(); assignmment.Created = DateTime.Now; assignmment.Modify = DateTime.Now; assignmment.Clients = Mapper.Map <List <ClientsVM> >(ClientsDAL.ReadClients()); assignmment.Positions = Mapper.Map <List <PositionsVM> >(PositionsDAL.ReadPositions()); return(View(assignmment)); }
public ActionResult Edit(AssignmentVM assignmentVM) { if (ModelState.IsValid) { db.Entry(assignmentVM.assignment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } //ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "FirstName", assignment.EmployeeID); //ViewBag.HardwareID = new SelectList(db.Hardwares, "ID", "Model", assignment.HardwareID); //ViewBag.SoftwareID = new SelectList(db.Softwares, "ID", "Name", assignment.SoftwareID); //ViewBag.VisioID = new SelectList(db.Softwares, "ID", "Name", assignment.VisioID); return(View(assignmentVM)); }
public AssignmentVM GetAssignment(int assignmentId, string userId = null) { var assignment = _context.Assignments.FirstOrDefault(a => a.Id == assignmentId); var response = new AssignmentVM(assignment); if (userId != null) { var submission = _context.AssignmentSubmissions.FirstOrDefault(a => a.UserId == userId && a.AssignmentId == assignmentId); if (submission != null) { response.MySubmission = new AssignmentSubmissionVM(submission); } } return(response); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { model.Culture = model.Culture == "ar-EG" ? "ar-EG" : "en-GB"; if (!ModelState.IsValid) { foreach (var item in ModelState) { if (ModelState["UserName"].Errors.Count > 0) { var req = item.Value.Errors.SingleOrDefault(a => a.ErrorMessage == "The UserName field is required."); item.Value.Errors.Remove(req); ModelState.AddModelError("UserName", MsgUtils.Instance.Trls("userNameRequired", model.Culture)); } else if (ModelState["Password"].Errors.Count > 0) { var req = item.Value.Errors.SingleOrDefault(a => a.ErrorMessage == "The Password field is required."); item.Value.Errors.Remove(req); ModelState.AddModelError("Password", MsgUtils.Instance.Trls("passWordRequired", model.Culture)); } } return(PartialView("Loginform", model)); } // #region License // string[] lines = System.IO.File.ReadAllLines(Server.MapPath(@"~/App_Data/App.txt")); // #endregion var db = new UserContext(); var user = dbc.Users.Where(u => u.UserName == model.UserName).FirstOrDefault(); if (user == null) { ModelState.AddModelError("Password", MsgUtils.Instance.Trls("incorrectError", model.Culture)); return(PartialView("Loginform", model)); } var excluded = new string[] { "admin", "hradmin" }; AssignmentVM assignment = null; // Check employee is active if (!excluded.Contains(model.UserName.ToLower())) { if (user.EmpId == null) { ModelState.AddModelError("UserName", MsgUtils.Instance.Trls("assignedError", model.Culture)); return(PartialView("Loginform", model)); } else { assignment = dbc.Database.SqlQuery <AssignmentVM>("select BranchId, DepartmentId, IsDepManager, JobId, PositionId, ManagerId from Assignments A where A.EmpId = " + user.EmpId + " and (CONVERT(date, GetDate()) BETWEEN A.AssignDate And A.EndDate) And A.sysAssignStatus = 1").FirstOrDefault(); if (assignment == null) { ModelState.AddModelError("UserName", MsgUtils.Instance.Trls("activateError", model.Culture)); //"Employee is not active" return(PartialView("Loginform", model)); } } } var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : true); switch (result) { case SignInStatus.Success: // reset Access failed account await UserManager.ResetAccessFailedCountAsync(user.Id); if (user.ResetPassword == true) { string vCode = await UserManager.GeneratePasswordResetTokenAsync(user.Id); if (vCode != string.Empty) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(); Session.Abandon(); Session.Clear(); return(RedirectToAction("ResetPassword", "Account", new ResetPasswordViewModel() { UserName = model.UserName, Code = vCode, OldPassword = model.Password })); } ModelState.AddModelError("Password", MsgUtils.Instance.Trls("incorrectError", user.Language)); return(PartialView("Loginform", model)); } Session["getUserId"] = user.Id.ToString(); Response.Cookies["userName"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["userEmpId"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["userCompanyId"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1); var domain = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); Response.Cookies.Add(new HttpCookie("userName", user.UserName) { Expires = DateTime.Now.AddDays(7) }); Response.Cookies.Add(new HttpCookie("rememberMe", model.RememberMe.ToString()) { Expires = DateTime.Now.AddDays(7) }); Response.Cookies.Add(new HttpCookie("culture", user.Language) { Expires = DateTime.Now.AddDays(7) }); if (model.RememberMe == true) { Response.Cookies.Add(new HttpCookie("password", model.Password) { Expires = DateTime.Now.AddDays(7) }); } if (user.LastLogin != null) { Response.Cookies.Add(new HttpCookie("lastLogin", user.LastLogin.Value.ToString("MM/dd/yyyy HH:mm:ss")) { Expires = DateTime.Now.AddDays(7) }); } string locaName; Response.Cookies.Add(new HttpCookie("welcomeMsg", Db.MsgUtils.Instance.Trls(user.Language, "Welcome")) { Expires = DateTime.Now.AddDays(7) }); if (user.EmpId != null && user.DefaultCompany != null) { locaName = _hrUnitOfWork.PeopleRepository.GetEpmLocalname((int)user.EmpId, user.Language); Response.Cookies.Add(new HttpCookie("userEmpId", user.EmpId.ToString()) { Expires = DateTime.Now.AddDays(7) }); Response.Cookies.Add(new HttpCookie("userCompanyId", user.DefaultCompany.Value.ToString()) { Expires = DateTime.Now.AddDays(7) }); } else { locaName = user.UserName; } Response.Cookies.Add(new HttpCookie("localName", locaName) { Expires = DateTime.Now.AddDays(7) }); UserLog loggedUser = new UserLog(); loggedUser.UserId = user.Id; loggedUser.LogEvent = 1; loggedUser.CompanyId = user.DefaultCompany.Value; loggedUser.StartTime = DateTime.Now; //Convert.ToDateTime(data.Value.ToString("H:mm")); user.AccessFailedCount = 0; user.LastLogin = DateTime.Now; //user.Locked = false; dbc.UserLogs.Add(loggedUser); int res = await dbc.SaveChangesAsync(); //set session variables if (assignment != null) { Session["DepartmentId"] = assignment.DepartmentId; Session["BranchId"] = assignment.BranchId; Session["PositionId"] = assignment.PositionId; Session["IsDepManager"] = assignment.IsDepManager.ToString(); Session["BranchId"] = assignment.BranchId; Session["JobId"] = assignment.JobId; } return(RedirectToLocal(returnUrl)); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.LockedOut: ModelState.AddModelError("UserName", MsgUtils.Instance.Trls("lockoutError", model.Culture)); return(PartialView("Loginform", model)); case SignInStatus.Failure: user.AccessFailedCount = user.AccessFailedCount + 1; int rest = db.SaveChanges(); var msg = MsgUtils.Instance.Trls("incorrectError", model.Culture); ModelState.AddModelError("Password", msg); return(PartialView("Loginform", model)); default: msg = MsgUtils.Instance.Trls("incorrectError", model.Culture); ModelState.AddModelError("Password", msg); return(PartialView("Loginform", model)); } }
public ActionResult DeleteAssignment(AssignmentVM assignment) { AssignmentDAL.DeleteAssignment(Mapper.Map <AssignmentDM>(assignment)); return(View()); }