public HomeController() { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = SessionVar.GetString("user_name"); lblError.Text = username; DataBaseManager.ConnectToSlashDatabase(); List <string> tagList = new List <string>(); foreach (ListItem item in lstTags.Items) { tagList.Add(item.Text); } try { DataBaseManager.InsertDealTransaction(username, txtTitle.Text, txtDescription.Text, tagList); DataBaseManager.CloseConnection(); } catch (Exception err) { lblError.Text = err.Message; } }
public ActionResult PlaceOrder() { CreateOrderIfRequired(); webShopModel.PaymentCompleted = null; try { MerchantOrder order = OrderHelper.PrepareOrder(Request.Form, webShopModel); if (order != null) { MerchantOrderResponse response = omniKassa.Announce(order); webShopModel = null; SessionVar.Set <WebShopModel>(SESSION_ORDER, null); return(new RedirectResult(response.RedirectUrl)); } } catch (RabobankSdkException ex) { webShopModel.Error = ex.Message; } catch (ArgumentException ex) { webShopModel.Error = ex.Message; } return(View("Index", webShopModel)); }
public ActionResult Supervisor(SupervisorLogIn model) { var response = new ResponseDTO <LoginResponseDTO>(); var caller = new LoginCaller(); bool redirect = false; try { if (ModelState.IsValid) { response = caller.GetLogin(new UserDTO() { UserName = model.sUser, Password = model.sPassword }); model.Message = (response.Success) ? string.Empty : response.Message; redirect = (response.Success && response.Result.IsAuthenticated) ? true : false; } } catch (System.Exception exception) { //Falta implementar el log ********** model.Message = Key.GetError(); } if (redirect) { SessionVar.SetLoginUser(response.Result); return(RedirectToAction("Administrator", "Menu")); } return(View(model)); }
private void CreateOrderIfRequired() { if (Session[SESSION_ORDER] == null) { webShopModel = new WebShopModel(GetOrder(++orderId)); SessionVar.Set <WebShopModel>(SESSION_ORDER, webShopModel); } }
private async Task <List <TicketViewModel> > GetTickets(string status, string userName) { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } var tickets = new List <TicketViewModel>(); using (var dataContext = new HelpDeskEntities()) { var data = new List <Ticket>(); if (!string.IsNullOrWhiteSpace(status) && !string.IsNullOrWhiteSpace(userName)) { data = await dataContext.Tickets.Include("Category").Where(t => t.IsDeleted.Equals(false) && t.Status.Equals(status) && t.CreatedBy.Equals(userName)).OrderByDescending(t => t.ModifiedDate).ToListAsync(); } else if (!string.IsNullOrWhiteSpace(status) && string.IsNullOrWhiteSpace(userName)) { data = await dataContext.Tickets.Include("Category").Where(t => t.IsDeleted.Equals(false) && t.Status.Equals(status)).OrderByDescending(t => t.ModifiedDate).ToListAsync(); } else if (string.IsNullOrWhiteSpace(status) && !string.IsNullOrWhiteSpace(userName)) { data = await dataContext.Tickets.Include("Category").Where(t => t.IsDeleted.Equals(false) && t.CreatedBy.Equals(userName)).OrderByDescending(t => t.ModifiedDate).ToListAsync(); } else { data = await dataContext.Tickets.Include("Category").Where(t => t.IsDeleted.Equals(false)).OrderByDescending(t => t.ModifiedDate).ToListAsync(); } if (data.Count > 0) { int i = 1; foreach (Ticket ticket in data) { tickets.Add(new TicketViewModel() { SN = i, TicketID = ticket.TicketID, TicketNo = ticket.TicketNo, Subject = ticket.Subject, Description = ticket.Description, Status = ticket.Status, CreatedBy = ticket.CreatedBy, CreationDate = ticket.CreationDate, CategoryID = ticket.CategoryID, ModifiedBy = ticket.ModifiedBy, ModifiedDate = ticket.ModifiedDate, Category = ticket.Category }); i++; } } } return(tickets); }
protected void Page_Load(object sender, EventArgs e) { DataBaseManager.ConnectToSlashDatabase(); SqlDataAdapter adapter = DataBaseManager.SelectTransactions(SessionVar.GetString("user_name")); DataSet ds = new DataSet(); adapter.Fill(ds, "transactions"); grvDeals.DataSource = ds; grvDeals.DataBind(); DataBaseManager.CloseConnection(); }
public async Task <ActionResult> RaiseTicket() { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } using (HelpDeskEntities dataContext = new HelpDeskEntities()) { ViewBag.Categories = await dataContext.Categories.ToListAsync(); } return(View()); }
protected void Page_Load(object sender, EventArgs e) { string userName = SessionVar.GetString("user_name"); if (isLogin()) { Response.Redirect("~/home/" + Server.UrlEncode(userName)); } else { Response.Redirect("~/login"); } }
public HomeController() { if (omniKassa == null) { omniKassa = Endpoint.Create(Environment.SANDBOX, SIGNING_KEY, TOKEN); } webShopModel = SessionVar.Get <WebShopModel>(SESSION_ORDER); if (webShopModel != null) { orderId = webShopModel.OrderId; orderItemId = webShopModel.GetLastItemId(); } }
protected void Page_Load(object sender, EventArgs e) { userName = SessionVar.GetString("user_name"); DataBaseManager.ConnectToSlashDatabase(); LoadDeals(); if (!Page.IsPostBack) { LoadTagsList(); LoadUserInfo(); } DataBaseManager.CloseConnection(); lblUserName.Text = userName; }
public ActionResult Update() { SessionVar.SetLoginUser(new DLL.Login.LoginResponseDTO() { User = new DLL.DB.UserDTO() { UserName = "******" } }); var model = new WorkerUpdate() { Client = new List <SelectListItem>(), Project = new List <SelectListItem>(), Location = new List <SelectListItem>(), Role = new List <SelectListItem>() }; model.Client.Add(new SelectListItem() { Text = Strings.SelectOption }); try { var invoker = new Invoker <List <DLL::CatalogsDTO>, bool>(new CompanyCaller <List <DLL::CatalogsDTO>, bool>()); var response = invoker.GetAll(new DLL::RequestDTO <bool>() { Signature = true }); foreach (DLL::CatalogsDTO item in response.Result) { model.Client.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }); } } catch (System.Exception ex) { DLLS::ExceptionHandler.Instance.WriteExceptionLog(ex); model.Message = Key.GetError(); } return(View(model)); }
private Boolean isLogin() { string key1 = SessionVar.GetString("login_key"); string key2 = Request.Cookies["login_key"].Value; Debug.WriteLine("test tag: key1 " + key1); Debug.WriteLine("test tag: key2 " + key2); if (key1.Equals(key2)) { return(true); } else { return(false); } }
public async Task <ActionResult> AuditTicket(TicketViewModel model) { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } if (!HomeController.IsMember(User.Identity.Name, ConfigurationManager.AppSettings["ADIAG"].ToString())) { Redirect("~/Account/AccessDenied"); } if (string.IsNullOrWhiteSpace(model.Description)) { return(Json(new { type = "danger", header = "Error", message = "Please enter a note for your action." })); } StringBuilder errors = new StringBuilder(); Guid id = model.TicketID; var isTicketUpdated = await IsTicketUpdated(model); if (isTicketUpdated.Item1) { GeneralSetting generalSetting = null; using (HelpDeskEntities dataContext = new HelpDeskEntities()) { generalSetting = await dataContext.GeneralSettings.FirstOrDefaultAsync(); if (generalSetting != null) { Ticket ticket = await dataContext.Tickets.FirstOrDefaultAsync(param => param.TicketID == model.TicketID); if (ticket != null) { // mail sender and ict string recipients = ticket.OwnerEmail + "," + generalSetting.RecipientEmails; SendEmail("ICT HelpDesk Re: [" + model.TicketNo + "] " + model.Subject, model.Description, recipients, id.ToString(), model.FileAttachments); } } } return(Json(new { type = "success", header = "Success", message = "" })); } return(Json(new { type = "danger", header = "Error", message = isTicketUpdated.Item2 })); }
public ActionResult Login() { var vm = new LoginPageViewModel { Username = "", Password = "", ErrorMessage = "" }; if (SessionVar.guidUsuario != null) { ClaseBitacora bitacora = new ClaseBitacora(); bitacora.Log(ClaseBitacora.TipoAccion.FIN, ""); } FormsAuthentication.SignOut(); SessionVar.reset(); return(View(vm)); }
protected void Page_Load(object sender, EventArgs e) { /* to fetch date from textbox */ txtDate.Attributes.Add("readonly", "readonly"); userName = SessionVar.GetString("user_name"); if (userName.Equals("")) { Response.Redirect("login"); } DataBaseManager.ConnectToSlashDatabase(); LoadTags(); if (!Page.IsPostBack) { LoadUserInfo(); } DataBaseManager.CloseConnection(); }
private void LoadTagsList() { try { string userName = SessionVar.GetString("user_name"); SqlDataReader reader = DataBaseManager.SelectUserTagsByName(userName); while (reader.Read()) { HyperLink link = new HyperLink(); link.ID = (string)reader["tag"]; link.Text = (string)reader["tag"]; link.CssClass = "list-group-item"; tagList.Controls.Add(link); } reader.Close(); } catch (Exception err) { Debug.WriteLine(err.Message); } }
public async Task <ActionResult> UpdateTicket(TicketViewModel model) { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } StringBuilder errors = new StringBuilder(); Guid id = model.TicketID; var isTicketUpdated = await IsTicketUpdated(model); if (isTicketUpdated.Item1) { GeneralSetting generalSetting = null; using (HelpDeskEntities dataContext = new HelpDeskEntities()) { generalSetting = await dataContext.GeneralSettings.FirstOrDefaultAsync(); if (generalSetting != null) { if (generalSetting.EnableEmailAlert && !string.IsNullOrWhiteSpace(generalSetting.RecipientEmails)) { Ticket ticket = await dataContext.Tickets.FirstOrDefaultAsync(param => param.TicketID == id); string recipients = ticket.OwnerEmail + "," + generalSetting.RecipientEmails; SendEmail("ICT HelpDesk Re: [" + model.TicketNo + "] " + model.Subject, model.Description, recipients, id.ToString(), model.FileAttachments); //if (HomeController.IsMember(User.Identity.Name, ConfigurationManager.AppSettings["ADAG"].ToString())) // SendEmail("ICT HelpDesk Re: [" + model.TicketNo + "] " + model.Subject, model.Description, model.OwnerEmail, id.ToString(), model.FileAttachments); //else // SendEmail("ICT HelpDesk Re: [" + model.TicketNo + "] " + model.Subject, model.Description, generalSetting.RecipientEmails, id.ToString(), model.FileAttachments); } } } return(RedirectToAction("TicketDetails", new RouteValueDictionary(new { controller = "Home", action = "TicketDetails", id = id }))); } return(RedirectToAction("TicketDetails", new RouteValueDictionary(new { controller = "Home", action = "TicketDetails", id = id, errors = isTicketUpdated.Item2 }))); }
protected void btnLogin_Click(object sender, EventArgs e) { try { DataBaseManager.ConnectToSlashDatabase(); int count = DataBaseManager.SelectUserCount(txtEmail.Text, txtPwd.Text); if (count != 1) { //TODO redirect to problem submit webpage //Response.Redirect() } else { SqlDataReader reader = DataBaseManager.SelectUser(txtEmail.Text, txtPwd.Text); reader.Read(); string name = (string)reader["username"]; SessionVar.Set <string>("user_name", name); string key = TextUtils.GetRandomLoginKey(); Debug.WriteLine("test tag generated key " + key); Response.Cookies["login_key"].Value = key; Response.Cookies["login_key"].Expires = DateTime.Now.AddDays(10); SessionVar.SetString("login_key", key); Debug.WriteLine("cookie key " + Response.Cookies["login_key"].Value); Response.Redirect("home/" + Server.UrlEncode(name)); } } catch (Exception err) { lblError.Text = err.Message.ToString(); } finally { DataBaseManager.CloseConnection(); } }
public ActionResult Administrator() { ViewBag.LoginUser = SessionVar.GetLoginUser(); return(View()); }
public ActionResult LogOut() { SessionVar.Clean(); return(RedirectToAction("Supervisor", "LogIn")); }
public void UpdateProfile(UpdateProfile profile) { using (var connection = GetConnection()) { if (UserSecretsConfigurationExtensions.) { connection.Execute("Update Student Set email_address = @emailAddress, mobile_number = @mobileNo where student_id = @Id", new { Id = SessionVar.GetInt("SID"), emailAddress = profile.Email, mobileNo = profile.Mobile }); } if (User.lecturer) { connection.Execute("Update Lecturer Set email_address = @emailAddress, contact_number = @mobileNo where lecturer_id = @Id", new { Id = SessionVar.GetInt("LID"), emailAddress = profile.Email, mobileNo = profile.Mobile }); } } }
public ActionResult Login() { SessionVar.Clear(); return(View()); }
protected void Session_Start(Object sender, EventArgs e) { SessionVar.GetInstance(HttpContext.Current); }
public async Task <ActionResult> RaiseTicket(TicketViewModel model) { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } Guid id = Guid.NewGuid(); bool isSuccessful = false; bool sendEmailAlert = false; GeneralSetting generalSetting = null; try { ViewBag.Categories = await new HelpDeskEntities().Categories.ToListAsync(); #region validate inputs StringBuilder errors = new StringBuilder(); if (string.IsNullOrWhiteSpace(model.Subject)) { errors.AppendLine("Subject is required."); } if (string.IsNullOrWhiteSpace(model.Description)) { errors.AppendLine("Description is required."); } if (model.CategoryID == null) { errors.AppendLine("Category is required."); } if (model.FileAttachments != null) { string[] unsupportedFileTypes = new[] { "exe" }; } #endregion if (errors.Length > 0) { for (int i = 0; i < errors.Length; i++) { ModelState.AddModelError("Error" + i.ToString(), errors[i].ToString()); } } else { // sanitize data model.Subject = SecurityHelper.Sanitize(model.Subject); model.Description = SecurityHelper.Sanitize(model.Description); #region save data using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (HelpDeskEntities dataContext = new HelpDeskEntities()) { string ticketNo = StringHelper.GenerateRandomNumber(5); model.TicketNo = ticketNo; Ticket ticket = new Ticket() { TicketID = id, TicketNo = ticketNo, CategoryID = model.CategoryID, Subject = model.Subject, Description = model.Description, Status = "N", CreatedBy = User.Identity.Name, CreationDate = DateTime.Now, ModifiedBy = User.Identity.Name, ModifiedDate = DateTime.Now, OwnerEmail = Session["userEmail"].ToString(), IsDeleted = false }; dataContext.Tickets.Add(ticket); if (await dataContext.SaveChangesAsync() > 0) { #region ticket files if (model.FileAttachments != null) { if (model.FileAttachments.Length > 0) { string targetPath = HttpContext.Server.MapPath(this.fileAttachmentPath); if (model.FileAttachments[0] != null) { List <TicketFile> ticketFiles = new List <TicketFile>(); foreach (var file in model.FileAttachments) { string fileName = Path.Combine(targetPath, file.FileName); file.SaveAs(fileName); ticketFiles.Add(new TicketFile() { TicketFileID = Guid.NewGuid(), TicketID = ticket.TicketID, FileName = file.FileName, FileForTOrN = "T", RefID = id, CreatedBy = User.Identity.Name, CreationDate = DateTime.Now, ModifiedBy = User.Identity.Name, ModifiedDate = DateTime.Now, IsDeleted = false }); } dataContext.TicketFiles.AddRange(ticketFiles); await dataContext.SaveChangesAsync(); } } } #endregion // trigger e-mail [optional] generalSetting = await dataContext.GeneralSettings.FirstOrDefaultAsync(); if (generalSetting != null) { if (generalSetting.EnableEmailAlert && !string.IsNullOrWhiteSpace(generalSetting.RecipientEmails)) { sendEmailAlert = true; } } transactionScope.Complete(); isSuccessful = true; } else { errors.AppendLine("Unknow error occured."); } } } #endregion } } catch (DbEntityValidationException ex) { HomeController.LogError(ex, HttpContext.Server.MapPath("~/Error_Log.txt")); } catch (Exception ex) { HomeController.LogError(ex, HttpContext.Server.MapPath("~/Error_Log.txt")); } if (isSuccessful) { if (sendEmailAlert) { SendEmail("ICT HelpDesk [" + model.TicketNo + "] " + model.Subject, model.Description, generalSetting.RecipientEmails, id.ToString(), model.FileAttachments); } return(RedirectToAction("TicketDetails", new RouteValueDictionary(new { controller = "Home", action = "TicketDetails", id = id }))); } return(View(model)); }
protected void Page_Load(object sender, EventArgs e) { lnkHome.NavigateUrl = "~/home/" + Server.UrlEncode(SessionVar.GetString("user_name")); }
protected void Page_Load(object sender, EventArgs e) { userName = SessionVar.GetString("user_name"); }
public ActionResult Login() { FormsAuthentication.SignOut(); SessionVar.reset(); return(View()); }
private async Task <Tuple <bool, string> > IsTicketUpdated(TicketViewModel model) { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } StringBuilder errors = new StringBuilder(); Guid id = model.TicketID; bool isSuccessful = false; try { #region validate inputs if (model.TicketID == null) { errors.AppendLine("Ticket ID is required."); } if (string.IsNullOrWhiteSpace(model.Description)) { errors.AppendLine("Description is required."); } if (model.FileAttachments != null) { string[] unsupportedFileTypes = new[] { "exe" }; } #endregion if (errors.Length > 0) { isSuccessful = false; } else { // sanitize data model.Description = SecurityHelper.Sanitize(model.Description); #region save data using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (HelpDeskEntities dataContext = new HelpDeskEntities()) { Ticket ticket = await dataContext.Tickets.FirstOrDefaultAsync(p => p.TicketID.Equals(model.TicketID)); if (ticket == null) { errors.AppendLine("Unknown ticket details"); } if (errors.Length == 0) { model.Subject = ticket.Subject; model.OwnerEmail = ticket.OwnerEmail; ticket.Status = model.Status; ticket.ModifiedBy = User.Identity.Name; dataContext.Entry(ticket).State = EntityState.Modified; if (await dataContext.SaveChangesAsync() > 0) { Guid ticketNoteID = Guid.NewGuid(); #region ticket note TicketNote ticketNote = new TicketNote() { TicketNoteID = ticketNoteID, TicketID = model.TicketID, Note = model.Description, CreatedBy = User.Identity.Name, CreationDate = DateTime.Now, ModifiedBy = User.Identity.Name, ModifiedDate = DateTime.Now, IsDeleted = false }; dataContext.TicketNotes.Add(ticketNote); if (await dataContext.SaveChangesAsync() > 0) { #region ticket files if (model.FileAttachments != null) { if (model.FileAttachments.Length > 0) { string targetPath = HttpContext.Server.MapPath(this.fileAttachmentPath); if (model.FileAttachments[0] != null) { List <TicketFile> ticketFiles = new List <TicketFile>(); foreach (var file in model.FileAttachments) { string fileName = Path.Combine(targetPath, file.FileName); file.SaveAs(fileName); ticketFiles.Add(new TicketFile() { TicketFileID = Guid.NewGuid(), TicketID = ticket.TicketID, FileName = file.FileName, FileForTOrN = "N", RefID = ticketNoteID, CreatedBy = User.Identity.Name, CreationDate = DateTime.Now, ModifiedBy = User.Identity.Name, ModifiedDate = DateTime.Now, IsDeleted = false }); } dataContext.TicketFiles.AddRange(ticketFiles); await dataContext.SaveChangesAsync(); } } } #endregion } #endregion transactionScope.Complete(); isSuccessful = true; } else { errors.AppendLine("Unknow error occured."); } } } } #endregion } } catch (DbEntityValidationException ex) { isSuccessful = false; HomeController.LogError(ex, HttpContext.Server.MapPath("~/Error_Log.txt")); } catch (Exception ex) { isSuccessful = false; errors.AppendLine(ex.Message); HomeController.LogError(ex, HttpContext.Server.MapPath("~/Error_Log.txt")); } return(Tuple.Create(isSuccessful, errors.ToString())); }
public async Task <ActionResult> TicketDetails(Guid id, string errors = "", string subject = "", string mailBody = "", string recipients = "") { if (string.IsNullOrWhiteSpace(SessionVar.GetString("displayName"))) { Redirect("~/Account/Login"); } Ticket ticket = new Ticket(); TicketViewModel ticketViewModel = new TicketViewModel(); try { using (HelpDeskEntities dataContext = new HelpDeskEntities()) { ticket = await dataContext.Tickets.Include("Category").FirstOrDefaultAsync(p => p.TicketID.Equals(id)); if (ticket != null) { ticket.TicketFiles = await dataContext.TicketFiles.Where(p => p.TicketID.Equals(id)).ToListAsync(); ticket.TicketNotes = await dataContext.TicketNotes.Where(p => p.TicketID.Equals(id)).ToListAsync(); ticketViewModel.TicketID = id; ticketViewModel.TicketNo = ticket.TicketNo; ticketViewModel.CategoryID = ticket.CategoryID; ticketViewModel.Category = ticket.Category; ticketViewModel.Description = ticket.Description; ticketViewModel.Status = ticket.Status; ticketViewModel.CreatedBy = ticket.CreatedBy; ticketViewModel.CreationDate = ticket.CreationDate; ticketViewModel.ModifiedBy = ticket.ModifiedBy; ticketViewModel.ModifiedDate = ticket.ModifiedDate; ticketViewModel.IsDeleted = ticket.IsDeleted; foreach (TicketFile item in ticket.TicketFiles) { ticketViewModel.TicketFileViewModels.Add(new TicketFileViewModel() { TicketID = ticket.TicketID, FileName = item.FileName, FileForTOrN = item.FileForTOrN, RefID = item.RefID, CreatedBy = item.CreatedBy, CreationDate = item.CreationDate, TicketViewModel = ticketViewModel }); } foreach (TicketNote item in ticket.TicketNotes) { ticketViewModel.TicketNoteViewModels.Add(new TicketNoteViewModel() { TicketID = ticket.TicketID, Note = item.Note, CreatedBy = item.CreatedBy, CreationDate = item.CreationDate, TicketViewModel = ticketViewModel }); } } } ViewBag.Errors = errors; } catch (Exception ex) { HomeController.LogError(ex, HttpContext.Server.MapPath("~/Error_Log.txt")); } return(View(ticketViewModel)); }