public ActionResult getCategoryList() { return(Json(db.tblPortfolioGalleries.Where(C => C.tblPortfolio.PortfolioID == _PortfolioID).DistinctBy(C => C.tblPortfolioGalleryCategory.PortfolioGalleryCategoryID).Select(Q => new { CategoryID = EncryptionDecryption.EncryptString(Q.tblPortfolioGalleryCategory.PortfolioGalleryCategoryID.ToString()), CategoryName = Q.tblPortfolioGalleryCategory.PortfolioGalleryCategoryName }).ToList(), JsonRequestBehavior.AllowGet)); }
public async Task <HttpResponseMessage> Reset(string token, string password) { if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(password)) { //validate token. Tuple <bool, string> result = this._tokenService.IsValid(token); if (result != null) { if (result.Item1 && !string.IsNullOrEmpty(result.Item2)) { //check user exist or not. var user = this._accountService.GetById(result.Item2); if (user != null) { //encrypte the password. var encryptedPassword = EncryptionDecryption.EncryptString(password, user.Email, AppSettingManager.Salt); this._accountService.ResetPassword(encryptedPassword, user.Id); //update async token Task.Run(() => this._tokenService.Deactivate(token)); //log change password activity. var requestInfo = ContextOperator.Get(ContextKeys.REQUEST_INFO_KEY) as Request; var actionLog = new ActivityLog { Id = Guid.NewGuid().ToString("N"), ActivityType = (byte)ActivityType.System, TargetObjectId = user.Id, CreatedBy = user.Id, Message = ActionLogMessage.CHANGED_PASSWORD, CreatedOn = DateTime.UtcNow, Platform = requestInfo?.Platform, Browser = requestInfo?.Browser, HostAddress = requestInfo?.HostAddress, HostName = requestInfo?.HostName, IsMobileDevice = requestInfo?.IsMobileDevice, Version = requestInfo?.Version, URI = requestInfo?.URI }; //add async action log. Task.Run(() => this._actionLogService.Add(actionLog)); return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(true, MessageString.CHANGED_PASSWORD, null)))); } return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.USER_NOT_EXISTS, null)))); } } return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.INVALID_TOKEN, null)))); } return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.INVALID_REQUEST_PARMS, null)))); }
public async Task <HttpResponseMessage> Login(LoginModel item) { if (ModelState.IsValid) { item.Password = EncryptionDecryption.EncryptString(item.Password, item.Email, AppSettingManager.Salt); var loginInfo = this._accountService.Login(item); if (loginInfo != null) { var session = new Session { Id = Guid.NewGuid().ToString("N"), UserId = loginInfo.Id, CompanyId = loginInfo.CompanyId, CreatedOn = DateTime.UtcNow }; this._sessionService.Add(session); //hash userId, companyId and sessionId loginInfo.Id = EncryptionDecryption.EncryptString(loginInfo.Id, AppSettingManager.Password, AppSettingManager.Salt); loginInfo.CompanyId = EncryptionDecryption.EncryptString(loginInfo.CompanyId, AppSettingManager.Password, AppSettingManager.Salt); loginInfo.SessionId = EncryptionDecryption.EncryptString(session.Id, AppSettingManager.Password, AppSettingManager.Salt); var requestInfo = ContextOperator.Get(ContextKeys.REQUEST_INFO_KEY) as Request; var loginHistory = new LoginHistory { Id = Guid.NewGuid().ToString("N"), UserId = loginInfo.Id, CreatedOn = DateTime.UtcNow, Platform = requestInfo?.Platform, Browser = requestInfo?.Browser, HostAddress = requestInfo?.HostAddress, HostName = requestInfo?.HostName, IsMobileDevice = requestInfo?.IsMobileDevice, Version = requestInfo?.Version, URI = requestInfo?.URI }; this._loginHistoryService.AddLog(loginHistory); var response = Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(true, MessageString.LOGGEDIN, loginInfo)); return(await Task.Run(() => response)); } } return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.INVALID_REQUEST_PARMS, null)))); }
public ActionResult CheckUserIsExistsOrNot() { try { if (ModelState.IsValid) { string strPhno = Request.Form["PhoneNo"]; string strPassword = EncryptionDecryption.EncryptString(Request.Form["Password"]); var data1 = db.tblCustomers.Where(c => c.PhoneNumber == strPhno.Trim()) .Where(c => c.Password == strPassword.Trim()).Where(c => c.IsActive == true).ToList(); var data2 = db.tblSystemUsers.Where(a => a.PhoneNumber == strPhno.Trim()) .Where(c => c.Password == strPassword.Trim()).ToList(); if (data1.Count > 0) { foreach (tblCustomer cust in data1) { Session["CustomerID"] = cust.CustomerID; Session["CustomerName"] = cust.CustomerName; Session["CustomerPhoneNumber"] = cust.PhoneNumber; } return(Json(new { UserExist = true, message = "" }, JsonRequestBehavior.AllowGet)); } else if (data2.Count > 0) { foreach (tblSystemUser SU in data2) { Session["UserID"] = SU.UserID; Session["UserName"] = SU.UserName; } return(Json(new { AdminExist = true, message = "" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { UserExist = false, message = "" }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new { UserExist = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { UserExist = true, message = "" }, JsonRequestBehavior.AllowGet)); }
public IActionResult Add([FromBody] UserTemplate user) { try { UserServiceResponse validation = Validate(user); if (validation != UserServiceResponse.Success) { return(Ok(new ServiceResponse <UserServiceResponse, UserTemplate>(validation))); } user.Password = EncryptionDecryption.EncryptString(_config.Value.HashKey, user.Password); var userMap = _mapper.Map <User>(user); _userRepository.Add(userMap); return(Ok(new ServiceResponse <UserServiceResponse, UserTemplate>(UserServiceResponse.Success))); } catch (System.Exception ex) { _logger.Error($"User Add :{ex}"); return(BadRequest(new ServiceResponse <UserServiceResponse, UserTemplate>(UserServiceResponse.Exception))); } }
public ActionResult InsertSystemUser() { if (Session["UserID"] == null && Session["UserName"] == null) { return(RedirectToAction("Login", "Login")); } try { if (ModelState.IsValid) { tblSystemUser SU = new tblSystemUser(); SU.UserName = Request.Form["UserName"]; string password = EncryptionDecryption.EncryptString(Request.Form["Password"]); SU.Password = password; SU.Email = Request.Form["Email"]; SU.PhoneNumber = Request.Form["PhoneNumber"]; SU.IsActive = true; SU.CreatedDate = DateTime.Now; db.tblSystemUsers.Add(SU); db.SaveChanges(); return(Json(new { success = true, message = "Record inserted successfully" }, JsonRequestBehavior.AllowGet)); } else { throw new Exception("Invalid Model State"); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult InsertCustomers() { if (Session["UserID"] == null && Session["UserName"] == null) { return(RedirectToAction("Login", "Login")); } long LastCustomerID = 0; try { if (ModelState.IsValid) { tblCustomer newCust = new tblCustomer(); newCust.CustomerName = Request.Form["CustomerName"]; newCust.Email = Request.Form["Email"]; string PhoneNumber = "91" + Request.Form["PhoneNumber"]; newCust.PhoneNumber = PhoneNumber.Trim(); string password = EncryptionDecryption.EncryptString(Request.Form["Password"]); newCust.Password = password; newCust.IsActive = Request.Form["IsActive"] == "true" ? true : false; newCust.CreatedDate = DateTime.Now; if (ModelState.IsValid) { int fileSize = 0; string fileName = string.Empty; string mimeType = string.Empty; System.IO.Stream fileContent; if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; fileSize = file.ContentLength; fileName = file.FileName; mimeType = file.ContentType; fileContent = file.InputStream; if (mimeType.ToLower() != "image/jpeg" && mimeType.ToLower() != "image/jpg" && mimeType.ToLower() != "image/png") { return(Json(new { Formatwarning = true, message = "Profile pic format must be JPEG or JPG or PNG." }, JsonRequestBehavior.AllowGet)); } #region Save And compress file //To save file, use SaveAs method file.SaveAs(Server.MapPath("~/CustomerProfile/") + fileName); if (!ImageProcessing.InsertImages(Server.MapPath("~/CustomerProfile/") + fileName)) { return(Json(new { success = false, message = "Error occur while uploading image." }, JsonRequestBehavior.AllowGet)); } #endregion } newCust.ProfilePic = fileName; } db.tblCustomers.Add(newCust); db.SaveChanges(); LastCustomerID = db.tblCustomers.Max(item => item.CustomerID); } return(Json(new { success = true, message = "Record inserted", lastcustomerid = LastCustomerID }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = "Error!" + ex.Message }, JsonRequestBehavior.AllowGet)); } }