public ActionResult DeleteAccount() { if (Session["UserID"] != null) { using (var database = new MvcTutorialEntities()) { int UserID = Convert.ToInt32(Session["UserID"]); var databaseUserAccount = database.tblUser.Find(UserID); if (databaseUserAccount != null) { database.tblUser.Remove(databaseUserAccount); Session.RemoveAll(); database.SaveChanges(); ViewBag.SuccessMessage = "Your Account is Deleted Successfully."; return(RedirectToAction("Registration", "User")); } else { return(RedirectToAction("Index", "Home")); } } } else { return(RedirectToAction("Login", "User")); } }
public ActionResult Login(UserLoginModelClass modeluserLoginData) { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { var Verify = database.tblUser.FirstOrDefault(user => user.MobileNo == modeluserLoginData.MobileNo && user.IsActive == true); if (Verify == null) { ViewBag.Message = "Mobile No does not exist."; } else { if (Verify.Password == modeluserLoginData.Password) { Session["UserID"] = Verify.UserID; Session["UserName"] = Verify.UserName; ViewBag.SuccessMessage = "Login SuccessFully."; return(RedirectToAction("Index", "Home")); } else { ViewBag.Message = "Mobile No or Password is wrong."; } } } } return(View()); }
public JsonResult EditCheckMobileNo(string MobileNo, int UserID) { using (var db = new MvcTutorialEntities()) { return(Json(!db.tblUser.Any(user => user.MobileNo == MobileNo && user.UserID != UserID), JsonRequestBehavior.AllowGet)); } }
public JsonResult EditCheckEmailAddress(string EmailAddress, int UserID) { using (var db = new MvcTutorialEntities()) { return(Json(!db.tblUser.Any(user => user.EmailAddress == EmailAddress && user.UserID != UserID), JsonRequestBehavior.AllowGet)); } }
public ActionResult ProfileInfo(UserProfileModelClass modelprofiledData) { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { int UserID = Convert.ToInt32(Session["UserID"]); var databaseData = database.tblUser.FirstOrDefault(user => user.UserID == UserID && user.IsActive == true); if (databaseData != null) { databaseData.MobileNo = modelprofiledData.MobileNo; databaseData.EmailAddress = modelprofiledData.EmailAddress; databaseData.Address = modelprofiledData.Address; database.SaveChanges(); ViewBag.SuccessMessage = "Profile Update Successfully."; return(View()); } else { ViewBag.Message = "Couldn't Find Your Profile."; } } } return(View()); }
public ActionResult AddEditEmployee(int EmployeeId) { MvcTutorialEntities db = new MvcTutorialEntities(); List <tblDepartment> departments = db.tblDepartments.ToList(); ViewBag.DeparmentList = new SelectList(departments, "DepartmentId", "DepartmentName"); EmployeeViewModel model = new EmployeeViewModel(); //edit if (EmployeeId > 0) { tblEmployee emp = db.tblEmployees.SingleOrDefault(x => x.EmployeeID == EmployeeId && x.isDeleted == false); model.EmployeeID = EmployeeId; model.DepartmentId = emp.DepartmentId; model.Name = emp.Name; model.Address = emp.Address; } // add return(PartialView("Partial2", model)); }
public List <Country> GetCountryList() { MvcTutorialEntities db = new MvcTutorialEntities(); List <Country> countries = db.Countries.ToList(); return(countries); }
public ActionResult ChangePassword(UserChangePasswordModelClass modelchangerPasswordData) { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { int UserID = Convert.ToInt32(Session["UserID"]); var verify = database.tblUser.FirstOrDefault(user => user.UserID == UserID && user.Password == modelchangerPasswordData.OldPassword && user.IsActive == true); if (verify != null) { verify.Password = modelchangerPasswordData.NewPassword; database.SaveChanges(); ViewBag.SuccessMessage = "Password Change Successfully. Please Re-Login With New Password."; Session.RemoveAll(); return(RedirectToAction("Login", "User")); } else { ViewBag.Message = "You have Enter Wrong Old Password."; } } } return(View()); }
public HttpResponseMessage CreateNewPassword(UserNewPasswordModelClass modelnewpasswordData) { try { if (ModelState.IsValid) { using (var db = new MvcTutorialEntities()) { var verify = db.tblUser.Find(modelnewpasswordData.UserID); if (verify != null) { verify.Password = modelnewpasswordData.NewPassword; db.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.NEWPASSWORD)); } else { return(this.GenerateResponse(false, HttpStatusCode.Unauthorized, Constants.UNOTHORIZED)); } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage ChangePassword(UserChangePasswordModelClass modelchangerPasswordData) { try { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { //int UserID = modelchangerPasswordData.UserID; var verify = database.tblUser.FirstOrDefault(user => user.UserID == modelchangerPasswordData.UserID && user.Password == modelchangerPasswordData.OldPassword && user.IsActive == true); if (verify != null) { verify.Password = modelchangerPasswordData.NewPassword; database.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.RESETPASSWORD)); //ViewBag.SuccessMessage = "Password Change Successfully. Please Re-Login With New Password."; } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.INVALIDPASSWORD)); //ViewBag.Message = "You have Enter Wrong Old Password."; } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult ProfileInfo() { if (Session["UserID"] != null) { using (var database = new MvcTutorialEntities()) { int UserID = Convert.ToInt32(Session["UserID"]); var databaseProfileData = database.tblUser.FirstOrDefault(user => user.UserID == UserID && user.IsActive == true); if (databaseProfileData != null) { UserProfileModelClass modelProfile = new UserProfileModelClass(); modelProfile.UserID = databaseProfileData.UserID; modelProfile.UserName = databaseProfileData.UserName; modelProfile.EmailAddress = databaseProfileData.EmailAddress; modelProfile.MobileNo = databaseProfileData.MobileNo; modelProfile.Address = databaseProfileData.Address; return(View(modelProfile)); } else { return(RedirectToAction("Index", "Home")); } } } else { return(RedirectToAction("Login", "User")); } }
// GET: Test public ActionResult Index() { MvcTutorialEntities db = new MvcTutorialEntities(); List <Employee> employees = db.Employee.ToList(); List <EmployeeViewModel> employeModels = employees.Where(x => x.Id > 0).Select(x => new EmployeeViewModel { name = x.name, adress = x.adress, Id = x.Id, departmentname = x.department.departmentname }).ToList(); ViewBag.employeList = employeModels; ViewBag.MyName = "METİN TEKİN"; List <string> Names = new List <string>(); Names.Add("Ayşe"); Names.Add("Merve"); Names.Add("Sıla"); ViewBag.Names = Names; //List<Employee> employes = new List<Employee>(); //employes.Add(new Employee { EmployeeId = 1, EmployeeName = "SARAH CUKA", Department = "IT" }); //employes.Add(new Employee { EmployeeId = 2, EmployeeName = "MARTIN GARRIX", Department = "GEO" }); //employes.Add(new Employee { EmployeeId = 3, EmployeeName = "TIM CRUL", Department = "HEA" }); //employes.Add(new Employee { EmployeeId = 4, EmployeeName = "MENSAH HAVAI", Department = "SP" }); //Employee emp = new Employee(); return(View()); }
public HttpResponseMessage ProfileInfo(int id) { try { if (id != 0) { using (var database = new MvcTutorialEntities()) { var databaseProfileData = database.tblUser.FirstOrDefault(user => user.UserID == id && user.IsActive == true); if (databaseProfileData != null) { UserProfileModelClass modelProfile = new UserProfileModelClass(); modelProfile.UserID = databaseProfileData.UserID; modelProfile.UserName = databaseProfileData.UserName; modelProfile.EmailAddress = databaseProfileData.EmailAddress; modelProfile.MobileNo = databaseProfileData.MobileNo; modelProfile.Address = databaseProfileData.Address; return(this.GenerateResponse(true, HttpStatusCode.OK, modelProfile)); } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND)); } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult Index(EmployeeViewModel model) { try { MvcTutorialEntities db = new MvcTutorialEntities(); List <tblDepartment> departments = db.tblDepartments.ToList(); ViewBag.DeparmentList = new SelectList(departments, "DepartmentId", "DepartmentName"); if (model.EmployeeID > 0) { //update tblEmployee emp = db.tblEmployees.SingleOrDefault(x => x.EmployeeID == model.EmployeeID && x.isDeleted == false); emp.DepartmentId = model.DepartmentId; emp.Name = model.Name; emp.Address = model.Address; db.SaveChanges(); } else { //insert tblEmployee emp = new tblEmployee(); emp.Address = model.Address; emp.Name = model.Name; emp.DepartmentId = model.DepartmentId; emp.isDeleted = false; db.tblEmployees.Add(emp); db.SaveChanges(); } return(View(model)); } catch (Exception) { throw; } }
public HttpResponseMessage DeactivateAccount(int id) { try { if (id != 0) { using (var database = new MvcTutorialEntities()) { var databaseUserAccount = database.tblUser.Find(id); if (databaseUserAccount != null) { databaseUserAccount.IsActive = false; database.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTDEACTIVATEDSUCCESSFULLY)); } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND)); } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult GetStateList(int CountryID) { MvcTutorialEntities db = new MvcTutorialEntities(); List <State> stateList = db.States.Where(x => x.CountryId == CountryID).ToList(); ViewBag.StateOption = new SelectList(stateList, "StateId", "StateName"); return(PartialView("StateOptionPartial")); }
public ActionResult ImageRetrieve(int imgID) { MvcTutorialEntities db = new MvcTutorialEntities(); var img = db.ImageStores.SingleOrDefault(x => x.ImageId == imgID); return(File(img.ImageByte, "image/jgp")); }
public ActionResult DeleteEmployee(int employeId) { MvcTutorialEntities db = new MvcTutorialEntities(); Employee employee = db.Employee.Where(e => e.Id == employeId).FirstOrDefault(); db.Employee.Remove(employee); db.SaveChanges(); return(View()); }
public ActionResult GetSeachRecord(string SearchText) { MvcTutorialEntities db = new MvcTutorialEntities(); List <EmployeeViewModel> list = db.tblEmployees.Where(x => x.Name.Contains(SearchText) || x.Address.Contains(SearchText) || x.tblDepartment.DepartmentName.Contains(SearchText)).Select(x => new EmployeeViewModel { Name = x.Name, EmployeeID = x.EmployeeID, DepartmentName = x.tblDepartment.DepartmentName, Address = x.Address }).ToList(); return(PartialView("SearchPartial", list)); }
public HttpResponseMessage ProfileInfo(UserProfileModelClass modelprofiledData) { try { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { // this validation is use when browser will disable javasript. if (database.tblUser.Any(email => email.EmailAddress == modelprofiledData.EmailAddress && email.EmailAddress != modelprofiledData.EmailAddress)) { return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.EMAILALREADYEXISTS)); } else if (database.tblUser.Any(Mobileno => Mobileno.MobileNo == modelprofiledData.MobileNo && Mobileno.MobileNo != modelprofiledData.MobileNo)) { return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.MOBILEALREADYEXISTS)); } else { var databaseData = database.tblUser.FirstOrDefault(user => user.UserID == modelprofiledData.UserID && user.IsActive == true); if (databaseData != null) { databaseData.MobileNo = modelprofiledData.MobileNo; databaseData.EmailAddress = modelprofiledData.EmailAddress; databaseData.Address = modelprofiledData.Address; database.Entry(databaseData).State = System.Data.Entity.EntityState.Modified; database.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.PROFILEUPDATE)); //ViewBag.SuccessMessage = "Profile Update Successfully."; //return View(); } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND)); //ViewBag.Message = "Couldn't Find Your Profile."; } } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult EmployeDetail(int ID) { MvcTutorialEntities db = new MvcTutorialEntities(); Employee employee = db.Employee.Where(x => x.Id == ID).FirstOrDefault(); EmployeeViewModel employeeViewModel = new EmployeeViewModel(); employeeViewModel.Id = employee.Id; employeeViewModel.name = employee.name; employeeViewModel.adress = employee.adress; employeeViewModel.departmentname = employee.department.departmentname; return(View(employeeViewModel)); }
public HttpResponseMessage ActivateAccount(UserActiveAccountClass modeluseractiveaccount) { try { using (var database = new MvcTutorialEntities()) { switch (modeluseractiveaccount.Action) { case "MobileVerify": var verifyMobile = database.tblUser.FirstOrDefault(user => user.MobileNo == modeluseractiveaccount.MobileNo); if (verifyMobile != null) { if (verifyMobile.IsActive == false) { return(this.GenerateResponse(true, HttpStatusCode.OK, verifyMobile.UserID)); } else { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.ACCOUNTDEALREADYACTIVE)); } } else { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.MOBILENOTEXISTS)); } case "PasswordVerify": var verifyPassword = database.tblUser.FirstOrDefault(user => user.UserID == modeluseractiveaccount.UserID && user.Password == modeluseractiveaccount.Password && user.IsActive == false); if (verifyPassword != null) { verifyPassword.IsActive = true; database.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTACTIVATEDSUCCESSFULLY)); } else { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.INVALIDPASSWORD)); } default: return(this.GenerateResponse(false, HttpStatusCode.NotAcceptable, Constants.INVALID)); } } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult ShowEmployee(int EmployeeId) { MvcTutorialEntities db = new MvcTutorialEntities(); List <EmployeeViewModel> listEmp = db.tblEmployees.Where(x => x.isDeleted == false && x.EmployeeID == EmployeeId).Select(x => new EmployeeViewModel { Name = x.Name, DepartmentName = x.tblDepartment.DepartmentName, Address = x.Address, EmployeeID = x.EmployeeID }).ToList(); ViewBag.EmployeeList = listEmp; return(PartialView("Partial1")); }
public JsonResult DeleteEmployee(int EmployeeId) { MvcTutorialEntities db = new MvcTutorialEntities(); bool result = false; tblEmployee emp = db.tblEmployees.SingleOrDefault(x => x.isDeleted == false && x.EmployeeID == EmployeeId); if (emp != null) { emp.isDeleted = true; db.SaveChanges(); result = true; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult RegisterUser(RegistrationViewModel model) { MvcTutorialEntities db = new MvcTutorialEntities(); tblSiteUser siteUser = new tblSiteUser(); siteUser.UserName = model.UserName; siteUser.EmailId = model.EmailId; siteUser.Address = model.Address; siteUser.Password = model.Password; siteUser.RoleId = 3; db.tblSiteUsers.Add(siteUser); db.SaveChanges(); return(View()); }
public JsonResult ImageUpload(ProductViewModel model) { MvcTutorialEntities db = new MvcTutorialEntities(); int imageId = 0; var file = model.ImageFile; byte[] imagebyte = null; if (file != null) { file.SaveAs(Server.MapPath("/UploadedImage/" + file.FileName)); BinaryReader reader = new BinaryReader(file.InputStream); imagebyte = reader.ReadBytes(file.ContentLength); ImageStore img = new ImageStore(); img.ImageName = file.FileName; img.ImageByte = imagebyte; img.ImagePath = "/UploadedImage/" + file.FileName; img.IsDeleted = false; db.ImageStores.Add(img); db.SaveChanges(); imageId = img.ImageId; } if (model.ImageUrl != null) { imagebyte = DownloadImage(model.ImageUrl); ImageStore img = new ImageStore(); img.ImageName = "Abc"; img.ImageByte = imagebyte; img.ImagePath = model.ImageUrl; img.IsDeleted = false; db.ImageStores.Add(img); db.SaveChanges(); imageId = img.ImageId; } return(Json(imageId, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage Registration(UserRegistrationModelClass modelUserRegisterData) { try { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { // this validation is use when browser will disable javasript. if (database.tblUser.Any(email => email.EmailAddress == modelUserRegisterData.EmailAddress)) { return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.EMAILALREADYEXISTS)); } else if (database.tblUser.Any(Mobileno => Mobileno.MobileNo == modelUserRegisterData.MobileNo)) { return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.MOBILEALREADYEXISTS)); } else { tblUser dbobjectuser = new tblUser(); dbobjectuser.UserName = modelUserRegisterData.UserName; dbobjectuser.MobileNo = modelUserRegisterData.MobileNo; dbobjectuser.EmailAddress = modelUserRegisterData.EmailAddress; dbobjectuser.Password = modelUserRegisterData.Password; dbobjectuser.Address = modelUserRegisterData.Address; dbobjectuser.IsActive = true; dbobjectuser.AccountCreateDate = System.DateTime.Now; database.tblUser.Add(dbobjectuser); database.SaveChanges(); return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTCREATEDSUCCESSFULLY)); } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.INVALID)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Login(UserLoginModelClass modeluserLoginData) { try { if (ModelState.IsValid) { using (var database = new MvcTutorialEntities()) { var Verify = database.tblUser.FirstOrDefault(user => user.MobileNo == modeluserLoginData.MobileNo); if (Verify == null) { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.MOBILENOTEXISTS)); } else { if (Verify.IsActive == true) { if (Verify.Password == modeluserLoginData.Password) { return(this.GenerateResponse(true, HttpStatusCode.OK, Verify)); } else { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.INVALIDPASSWORD)); } } else { return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.ACCOUNTINACTIVE)); } } } } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA)); } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult _PartialEmployeDetail(int ID) { MvcTutorialEntities db = new MvcTutorialEntities(); Employee employee = db.Employee.Where(x => x.Id == ID).FirstOrDefault(); EmployeeViewModel employeeViewModel = new EmployeeViewModel(); employeeViewModel.Id = employee.Id; employeeViewModel.name = employee.name; employeeViewModel.adress = employee.adress; employeeViewModel.departmentname = employee.department.departmentname; ViewBag.Id = employee.Id; ViewBag.name = employee.name; ViewBag.adress = employee.adress; ViewBag.departmentname = employee.department.departmentname; return(PartialView("/Views/Shared/_PartialEmployeDetail.cshtml")); }
public HttpResponseMessage ProductList() { try { using (var database = new MvcTutorialEntities()) { var ProductList = database.tblProducts.ToList(); if (ProductList != null) { return(this.GenerateResponse(true, HttpStatusCode.OK, ProductList)); } else { return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND)); } } } catch (Exception ex) { return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex)); } }