public async Task <IActionResult> PutAdminDetail(int id, AdminDetail adminDetail) { if (id != adminDetail.AdminId) { return(BadRequest()); } _context.Entry(adminDetail).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdminDetailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("PkAdminId,EmployeeId,FirstName,LastName,DateOfBirth,Email,Contact,Pswd,Address,FatherName,CreatedDate,IsActive,IsDeleted")] AdminDetail adminDetail) { if (id != adminDetail.PkAdminId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(adminDetail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdminDetailExists(adminDetail.PkAdminId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(adminDetail)); }
public async Task <ActionResult <AdminDetail> > PostAdminDetail(AdminDetail adminDetail) { _context.AdminDetails.Add(adminDetail); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAdminDetail", new { id = adminDetail.AdminId }, adminDetail)); }
public async Task <ActionResult <AdminDetail> > PostAdminDetail([FromForm] AdminDetail adminDetail) { ActionResponses actionResponses; if (UserExists(adminDetail.fUsername)) { if (AdminDetailExists(adminDetail.fUsername)) { actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "1"); InsertLog("Create User Detail", "Execution Failed", "1"); return(CreatedAtAction("GetAdminDetail", actionResponses)); } _context.tAdminDetail.Add(adminDetail); await _context.SaveChangesAsync(); actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "0"); InsertLog("Create User Detail", "Execution Success", "0"); return(CreatedAtAction("GetAdminDetail", actionResponses)); } else { actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "3"); InsertLog("Create User Detail", "Execution Failed", "3"); return(CreatedAtAction("GetAdminDetail", actionResponses)); } }
public ActionResult Login(AdminDetail adminDetail, FormCollection formCollection) { string user = formCollection["Username"]; string pass = formCollection["Password"]; var adminResult = entities.AdminDetails.Where(s => s.Username == user && s.Password == pass).FirstOrDefault(); if (adminResult != null) { Session["Username"] = adminResult.Username; Session["EmployeeNumber"] = adminResult.EmployeeNumber; return(RedirectToAction("Welcome", "Admin")); } else { var userResult = entities.UserRegistrationDetails.Where(q => q.Username == adminDetail.Username && q.Password == adminDetail.Password).FirstOrDefault(); if (userResult == null) { // return View(); return(Content("<script language='javascript' type='text/javascript'>alert('User Not Found');window.location = 'Index';</script>")); } else { Session["Username"] = userResult.Username; Session["EmployeeNumber"] = userResult.EmployeeNumber; return(RedirectToAction("UserLogin", "User")); } } }
public async Task <IActionResult> PutAdminDetail(string id, [FromForm] AdminDetail adminDetail) { ActionResponses actionResponses; if (id != adminDetail.fUsername) { return(BadRequest()); } using (_context) { var entity = _context.tAdminDetail.FirstOrDefault(item => item.fUsername == id); if (entity != null) { entity.fUsername = adminDetail.fUsername; entity.fFirstName = adminDetail.fFirstName; entity.fLastName = adminDetail.fLastName; entity.fGender = adminDetail.fGender; _context.SaveChanges(); InsertLog("Modify Admin Extended Information", "Execution Success", "0"); actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "0"); return(CreatedAtAction("GetAdminDetail", actionResponses)); } } return(NoContent()); }
public ActionResult Save(AdminDetail adminDetail) { if (!ModelState.IsValid) { return(View("Index")); } if (_context.AdminDetails.Any(x => x.StoreId == adminDetail.StoreId)) { ViewBag.DuplicateMessage = "Store ID Already exists"; return(View("Index")); } if (adminDetail.Id == 0) { _context.AdminDetails.Add(adminDetail); } else { var adminDetailInDb = _context.AdminDetails.Single(p => p.Id == adminDetail.Id); adminDetailInDb.Location = adminDetail.Location; adminDetailInDb.Password = adminDetail.Password; adminDetailInDb.StoreId = adminDetail.StoreId; adminDetailInDb.Username = adminDetail.Username; adminDetailInDb.AdminName = adminDetail.AdminName; adminDetailInDb.EmailAddress = adminDetail.EmailAddress; } _context.SaveChanges(); return(Content("Congratulations")); }
public ActionResult DoiMatKhau(int id) { AdminDetail admin = new AdminDetail(); AdminAccount ac = admin.Tim(id); ViewBag.ac = ac; return(View()); }
//Admin Profile public ActionResult AdminProfile() { AdminDetail admin = new AdminDetail(); List <AdminAccount> detail = admin.DSAdmin(); ViewBag.detail = detail; return(View()); }
public async Task <IActionResult> Create([Bind("PkAdminId,EmployeeId,FirstName,LastName,DateOfBirth,Email,Contact,Pswd,Address,FatherName,CreatedDate,IsActive,IsDeleted")] AdminDetail adminDetail) { if (ModelState.IsValid) { _context.Add(adminDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(adminDetail)); }
public ActionResult Post(AdminDetail adminLogin) { var admin1Login = _context.AdminDetails.Where(x => x.AdminName == adminLogin.AdminName && x.Password == adminLogin.Password).FirstOrDefault(); if (admin1Login == null) { return(Content("Invalid Data")); } return(Content("Congratulations")); }
public ActionResult EditDetails(AdminDetail adminDetails) { AdminDetail DBAdmindata = adhyapanDB.GetAdminDetails("Admin"); ViewBag.User_Id = DBAdmindata.User_Id.ToString(); ViewBag.Password = DBAdmindata.Password.ToString(); ViewBag.Email = DBAdmindata.Email_Id.ToString(); if (!String.IsNullOrEmpty(adminDetails.status)) { ViewBag.status = adminDetails.status; } return(View("EditDetails")); }
public ActionResult ResultDoiMatKhau(int id, string password) { AdminDetail admin = new AdminDetail(); int tmp = admin.DoiMatKhau(id, password); if (tmp != 0) { ViewBag.Message = "Success"; } else { ViewBag.Message = "Failed"; } return(View()); }
private bool Authenticate(string userId, string password) { AdminDetail adminDetails = adhyapanDB.GetAdminDetails(userId); string decryptPassword = String.Empty; decryptPassword = Decrypt(adminDetails.Password.ToString()); if (userId.ToLower() == adminDetails.User_Id.ToString().ToLower() && password == decryptPassword) { return(true); } else { return(false); } }
public string SaveAdminDetails(AdminDetail adminDetail) { dateTime = DateTime.UtcNow.AddHours(5).AddMinutes(30); string result = Failed; try { using (DBEntities TestEngineDBContext = new DBEntities()) { var admin = TestEngineDBContext.AdminDetails.FirstOrDefault(x => x.ID == adminDetail.ID); if (admin == null) { admin = new AdminDetail(); admin.CreatedDate = dateTime; admin.Email = adminDetail.Email; admin.ID = Guid.NewGuid(); admin.Isdeleted = false; admin.ModifiedDate = dateTime; admin.Password = adminDetail.Password; admin.PhoneNumber = adminDetail.PhoneNumber; admin.Role = adminDetail.Role; admin.Name = adminDetail.Name; admin.UserName = adminDetail.UserName; admin.IsSuperAdmin = false; TestEngineDBContext.AdminDetails.Add(admin); } else { admin.Email = adminDetail.Email; admin.ModifiedDate = dateTime; admin.Password = adminDetail.Password; admin.PhoneNumber = adminDetail.PhoneNumber; admin.Role = adminDetail.Role; admin.UserName = adminDetail.UserName; admin.Name = adminDetail.Name; admin.Isdeleted = false; } TestEngineDBContext.SaveChanges(); result = Success; } } catch (Exception ex) { } return(result); }
public ActionResult AddAdmin(AdminDetail _pmodel) { AdminManageDetail _newuser = new AdminManageDetail() { UserName = _pmodel.UserName, Password = _pmodel.Password, ADOB = _pmodel.ADOB, Email = _pmodel.Email }; string msg = AdminManage.AddAdmininDB(_newuser); if (msg == "Success") { return(RedirectToAction("Index", "Patient")); } else { return(View(_pmodel)); } }
//function to check if User is valid or not public AdminDetail IsValidUser(AdminLoginViewModel model) { using (var dataContext = new AttendanceMarkingEntities1()) { //Retireving the user details from DB based on username and password enetered by user. AdminDetail user = dataContext.AdminDetails.Where(query => query.AdminId.Equals(model.AdminId) && query.Password.Equals(model.Password)).SingleOrDefault(); //If user is present, then true is returned. if (user == null) { return(null); } //If user is not present false is returned. else { return(user); } } }
public ActionResult SaveRegisterDetails(AdminDetail registerDetails) { //We check if the model state is valid or not. We have used DataAnnotation attributes. //If any form value fails the DataAnnotation validation the model state becomes invalid. if (ModelState.IsValid) { //create database context using Entity framework using (var databaseContext = new AttendanceMarkingEntities()) { //If the model state is valid i.e. the form values passed the validation then we are storing the User's details in DB. AdminDetail reglog = new AdminDetail(); //Save all details in RegitserUser object reglog.FirstName = registerDetails.FirstName; reglog.LastName = registerDetails.LastName; reglog.Age = registerDetails.Age; reglog.Gender = registerDetails.Gender; reglog.ContactNumber = registerDetails.ContactNumber; reglog.AdminId = registerDetails.AdminId; reglog.Password = registerDetails.Password; if (databaseContext.AdminDetails.Any(x => x.AdminId == reglog.AdminId)) { ViewBag.DuplicateMessage = "AdminId already exist."; return(View("SaveRegisterDetails", reglog)); } //Calling the SaveDetails method which saves the details. databaseContext.AdminDetails.Add(reglog); databaseContext.SaveChanges(); } ViewBag.Message = registerDetails.FirstName + " " + registerDetails.LastName + " your Details Sucessfully Saved"; //return View("Register"); return(View("Register")); return(RedirectToAction("Login")); } else { //If the validation fails, we are returning the model object with errors to the view, which will display the error messages. return(View("Register", registerDetails)); } }
public ActionResult EditEmail(AdminDetail adminDetails) { AdminDetail DBAdmindata = adhyapanDB.GetAdminDetails(adminDetails.User_Id.ToString()); if (adminDetails.Password.ToString() != Decrypt(DBAdmindata.Password.ToString())) { adminDetails.Password = null; adminDetails.status = "Fail: Currect password does not match"; } else { adhyapanDB.SetAdminDetails(adminDetails, "email"); adminDetails.Password = null; adminDetails.status = "Success: Email has been updated Updated"; } return(RedirectToAction("EditDetails", "Admin", adminDetails)); //return View("EditDetails", adminDetails); }
public ActionResult EditPassword(AdminDetail adminDetails) { AdminDetail DBAdmindata = adhyapanDB.GetAdminDetails(adminDetails.User_Id.ToString()); if (adminDetails.Password.ToString() != Decrypt(DBAdmindata.Password.ToString())) { adminDetails.Password = null; adminDetails.status = "Fail: Currect password does not match"; } else { adminDetails.Confirm_New_Password = encrypt(adminDetails.Confirm_New_Password.ToString()); adhyapanDB.SetAdminDetails(adminDetails, "password"); adminDetails.Password = null; adminDetails.status = "Success: Password Updated"; } return(RedirectToAction("EditDetails", adminDetails)); //return View("EditDetails", adminDetails); }
public ActionResult Register(RegisterDetail registerdetails) { if (ModelState.IsValid) { try { //List<string> ids = registerdetails.R_Id.ToString(); //registerdetails.R_Id= int id = db.RegisterDetails.Max(x => x.R_Id); registerdetails.R_Id = id + 1; db.RegisterDetails.Add(registerdetails); ViewBag.registermsg = "Registered Successfully!"; db.SaveChanges(); var user = db.RegisterDetails.Single(u => u.R_Id == registerdetails.R_Id); if (user.R_Role == "Customer") { CustomerDetail customerdetails = new CustomerDetail(user.R_Id, user.R_Username); db.CustomerDetails.Add(customerdetails); db.SaveChanges(); ViewBag.registermsg = "Registered Successfully!"; } if (user.R_Role == "Admin") { AdminDetail Admindetails = new AdminDetail(user.R_Id, user.R_Username); db.AdminDetails.Add(Admindetails); db.SaveChanges(); } } catch (Exception e) { ViewBag.message = e.Message; } } return(View()); }
public ActionResult AddAdministrator(AddAdministrator obj) { if (ModelState.IsValid) { // check if EmailID already exists or not bool EmailIDalreadyexists = dobj.Users.Where(x => x.EmailID == obj.Email).Any(); if (EmailIDalreadyexists) { ModelState.AddModelError("EmailID", "EmailID already exists"); obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList(); return(View(obj)); } // get logged in superadmin var superadmin = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault(); //create object of user //set default password for admin is Admin@123 //admin can change password after login through change password page NotesMarketPlace.Context.Users user = new NotesMarketPlace.Context.Users { FirstName = obj.FirstName.Trim(), LastName = obj.LastName.Trim(), RoleID = 2, EmailID = obj.Email.Trim(), Password = "******", IsEmailVerified = true, CreatedDate = DateTime.Now, CreatedBy = superadmin.ID, IsActive = true }; dobj.Users.Add(user); dobj.SaveChanges(); // get saved admin id var addedadmin = dobj.Users.Find(user.ID); // crate userprofile object AdminDetail userProfile = new AdminDetail { AdminID = addedadmin.ID, CountryCode = obj.CountryCode.Trim(), PhoneNumber = obj.PhoneNumber.Trim(), CreatedDate = DateTime.Now, CreatedBy = superadmin.ID }; // save object in admindetail database dobj.AdminDetail.Add(userProfile); dobj.SaveChanges(); return(RedirectToAction("ManageAdministrator")); } else { obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList(); return(View(obj)); } }
public ActionResult MyProfile(AdminProfile obj) { // get logged in user var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { // get logged in user profile var userprofile = dobj.AdminDetail.Where(x => x.AdminID == user.ID).FirstOrDefault(); if (userprofile != null) { // check if secondary email is already exists in User or Admin table or not // if email already exists then give error bool secondaryemailalreadyexistsinusers = dobj.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any(); bool secondaryemailalreadyexistsinadmin = dobj.AdminDetail.Where(x => x.SecondaryEmail == obj.Email && x.AdminID != user.ID).Any(); if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinadmin) { ModelState.AddModelError("SecondaryEmail", "This email address is already exists"); obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList(); return(View(obj)); } // update user's data user.FirstName = obj.FirstName.Trim(); user.LastName = obj.LastName.Trim(); // update userprofile's data if (obj.SecondaryEmail != null) { userprofile.SecondaryEmail = obj.SecondaryEmail.Trim(); } userprofile.CountryCode = obj.CountryCode.Trim(); userprofile.PhoneNumber = obj.PhoneNumber.Trim(); // user upploaded profile picture and there is also previous profile picture then delete previous profile picture if (userprofile.ProfilePicture != null && obj.ProfilePicture != null) { string path = Server.MapPath(userprofile.ProfilePicture); FileInfo file = new FileInfo(path); if (file.Exists) { file.Delete(); } } // save new profile picture and update data in userprofile table if (obj.ProfilePicture != null) { // get extension string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName); // set new name of file string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension; // set where to save picture string profilepicturepath = "~/Members/" + userprofile.AdminID + "/"; // create directory if not exists CreateDirectoryIfMissing(profilepicturepath); // get physical path and save profile picture there string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename); obj.ProfilePicture.SaveAs(path); // save path in database userprofile.ProfilePicture = profilepicturepath + newfilename; } userprofile.ModifiedDate = DateTime.Now; userprofile.ModifiedBy = user.ID; dobj.Entry(user).State = EntityState.Modified; dobj.Entry(userprofile).State = EntityState.Modified; dobj.SaveChanges(); } else { AdminDetail admin = new AdminDetail(); admin.AdminID = user.ID; bool secondaryemailalreadyexistsinusers = dobj.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any(); bool secondaryemailalreadyexistsinuserprofile = dobj.AdminDetail.Where(x => x.SecondaryEmail == obj.Email && x.AdminID != user.ID).Any(); if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinuserprofile) { ModelState.AddModelError("SecondaryEmail", "This email address is already exists"); obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList(); return(View(obj)); } // update user's data user.FirstName = obj.FirstName.Trim(); user.LastName = obj.LastName.Trim(); // update userprofile's data if (obj.SecondaryEmail != null) { admin.SecondaryEmail = obj.SecondaryEmail.Trim(); } admin.CountryCode = obj.CountryCode.Trim(); admin.PhoneNumber = obj.PhoneNumber.Trim(); // user upploaded profile picture and there is also previous profile picture then delete previous profile picture if (admin.ProfilePicture != null && obj.ProfilePicture != null) { string path = Server.MapPath(admin.ProfilePicture); FileInfo file = new FileInfo(path); if (file.Exists) { file.Delete(); } } // save new profile picture and update data in userprofile table if (obj.ProfilePicture != null) { // get extension string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName); // set new name of file string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension; // set where to save picture string profilepicturepath = "~/Members/" + userprofile.AdminID + "/"; // create directory if not exists CreateDirectoryIfMissing(profilepicturepath); // get physical path and save profile picture there string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename); obj.ProfilePicture.SaveAs(path); // save path in database admin.ProfilePicture = profilepicturepath + newfilename; } dobj.AdminDetail.Add(admin); dobj.SaveChanges(); dobj.Entry(user).State = EntityState.Modified; dobj.SaveChanges(); } return(RedirectToAction("Dashboard", "Admin")); } else { obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList(); return(View(obj)); } }
// GET: admin public ActionResult Index() { var db = new ApplicationDbContext(); var currentUserId = User.Identity.GetUserId(); var currentUser = db.Users.Find(currentUserId); if (!User.IsInRole("AdminRole")) { return(RedirectToAction("index", "Home")); } AdminDetail ad = new AdminDetail(); var d = DateTime.Now; ad.usersLastMonth = new List <UsersLastMonthCount>(); ad.questionsLastMonth = new List <QuestionsLastMonthCount>(); ad.activeUsersCount = db.Users.Where(u => u.isDeleted == false).Count(); ad.activeFemalesCount = db.Users.Where(u => u.isDeleted == false && u.Sex == "female").Count(); ad.activeMalesCount = db.Users.Where(u => u.isDeleted == false && u.Sex == "male").Count(); ad.todayUsersCount = db.Users.Where(u => u.isDeleted == false && u.RegistrationDate.Year == d.Year && u.RegistrationDate.Month == d.Month && u.RegistrationDate.Day == d.Day).Count(); for (int i = 0; i < 30; i++) { var date = d.ToString("dd.MM.yyyy"); var count = db.Users.Where(u => u.isDeleted == false && u.RegistrationDate.Year == d.Year && u.RegistrationDate.Month == d.Month && u.RegistrationDate.Day == d.Day).Count(); ad.usersLastMonth.Add(new UsersLastMonthCount() { date = date, count = count }); d = d.AddDays(-1); } ad.usersLastMonth = ad.usersLastMonth.OrderBy(_ord => DateTime.ParseExact(_ord.date, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture)).ToList(); d = DateTime.Now; ad.activeQuestionsCount = db.questions.Where(q => q.IsDeleted == false).Count(); ad.todayQuestionsCount = db.questions.Where(u => u.IsDeleted == false && u.QuestionCreated.Year == d.Year && u.QuestionCreated.Month == d.Month && u.QuestionCreated.Day == d.Day).Count(); for (int i = 0; i < 30; i++) { var date = d.ToString("dd.MM.yyyy"); var count = db.questions.Where(u => u.IsDeleted == false && u.QuestionCreated.Year == d.Year && u.QuestionCreated.Month == d.Month && u.QuestionCreated.Day == d.Day).Count(); ad.questionsLastMonth.Add(new QuestionsLastMonthCount() { date = date, count = count }); d = d.AddDays(-1); } ad.questionsLastMonth = ad.questionsLastMonth.OrderBy(_ord => DateTime.ParseExact(_ord.date, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture)).ToList(); ad.activeVotesCount = db.votes.Where(v => v.IsDeleted == false).Count(); return(View(ad)); }