public JsonResult DeleteFile(string id) { if (String.IsNullOrEmpty(id)) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Result = "Error" })); } try { UploadFile UploadFile = db.UploadFiles.Find(Int32.Parse(id)); if (UploadFile == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(new { Result = "Error" })); } //Remove from database db.UploadFiles.Remove(UploadFile); db.SaveChanges(); //Delete file from the file system var path = Path.Combine(Server.MapPath("~/UploadFile/"), UploadFile.FolderName + "/" + UploadFile.SaveFileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult ChangeCurrentCulture(int id) { // // Change the current culture for this user. // CultureHelper.CurrentCulture = id; // // Cache the new current culture into the user HTTP session. // Session["CurrentCulture"] = id; int SID = Convert.ToInt32(Session["LoginUserID"]); if (SID > 0) { User user = db.Users.FirstOrDefault(u => u.ID == SID); user.Language = id; db.SaveChanges(); } // // Redirect to the same page from where the request was made! \ // if (Request.UrlReferrer != null && !Request.UrlReferrer.LocalPath.Equals("/Account/Login")) { return(Redirect(Request.UrlReferrer.ToString())); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Create([Bind(Include = "ID,EmployeeID,UserID,UserPassword,Security")] User user) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "Name", user.EmployeeID); return(View(user)); }
public ActionResult Login(User model) { if (ModelState.IsValid) { var user = db.Users.FirstOrDefault(u => u.UserID.Equals(model.UserID)); if (user == null) { ModelState.AddModelError(string.Empty, "Notthing UserID"); } else { if (user.UserPassword == null || user.UserPassword.Equals("")) { return(RedirectToAction("Register", "Account", model)); } else if (user.UserPassword.Equals(model.UserPassword)) { Session["LoginUserID"] = user.ID; Session["LoginUserEmployeeID"] = user.EmployeeID; Session["LoginUserEmployeeName"] = user.Employee.Name; Session["LoginUserSecurity"] = user.Security; Session["LastLogin"] = user.LastLogin; user.LastLogin = DateTime.Now; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); // return RedirectToAction("Index", "Home"); return(RedirectToAction("ChangeCurrentCulture", "Home", new { id = user.Language })); } else { ModelState.AddModelError(string.Empty, "Recheck UserPassword"); } } } return(View(model)); }