public ActionResult LogIn(LogInModel model, string returnUrl) { if (ModelState.IsValid) { //call the service to check the username and password bool validateUser = new UserServ.WCFUserClient().LogIn(model.Username,model.PasswordToken); if (validateUser) { //works but dont understand yet //FormsAuthentication.SetAuthCookie(model.Username,true); List<UserType> userTypes = new WCFUserClient().GetUserUserType(model.Username).ToList(); string roles = ""; foreach (UserType u in userTypes) { if (roles != "") { roles = roles + "," + u.Name; } else { roles = u.Name; } } FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, model.Username, //user id DateTime.Now, DateTime.Now.AddMinutes(20), // expiry true, //do not remember roles, "/"); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); // if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Home", "Product"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public JsonResult UpdateFault(string faultID, string selectedStatusID) { try { Fault sF = new WCFFaultClient().GetFault(new Guid(faultID)); sF.Status = new Guid(selectedStatusID); new WCFFaultClient().UpdateFault(sF); Log l = new Log(); l.ID = Guid.NewGuid(); l.FaultID = sF.ID; l.Details = sF.Details; l.Date = DateTime.Now; l.Status = sF.Status; new WCFFaultClient().AddFaultToLog(l); User user = new WCFUserClient().GetUser(sF.Username); Status s = new WCFFaultClient().GetStatusByID(l.Status); new WCFBAFuncClient().SendEmail(user.Email, "Product Status Change", "Your Product " + sF.ProductID + " Status Has been changed to " + s.Detail); //MSG works commented for testing // SensMsg(user.Mobile, s.Detail, sF.ProductID); return Json("Success"); } catch (Exception) { return Json("Fail"); } }
//---------------------------------------Printing--------------------------------------------------- public FileResult PrintProductFaults() { Guid orderID =(Guid)Session["orderIDForPrint"]; Guid prID = (Guid)Session["productIDForPrint"]; Order order = new WCFCart_OrderClient().GetOrder(orderID); Order_Product op = new WCFCart_OrderClient().GetOrderProduct(orderID,prID); Fault fault = new WCFFaultClient().GetProductFaultByOrderID(orderID, prID); Product p = new WCFProductClient().GetProductByID(prID); List<Log> logs = new WCFFaultClient().GetLogByFaultID(fault.ID).ToList(); ; decimal totalAmount = p.Price * op.Quantity; // Create a Document object var document = new Document(PageSize.A4, 50, 50, 25, 25); // Create a new PdfWriter object, specifying the output stream var output = new FileStream("C:\\Users\\Kappuna\\Documents\\GitHub\\DSAAssignment1Sit1\\MVCAssignment - Copy\\MVCAssignment\\Content\\TempReports\\" + fault.Barcode + "Report.pdf", FileMode.Create); var writer = PdfWriter.GetInstance(document, output); // Open the Document for writing document.Open(); var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD); var subTitleFont = FontFactory.GetFont("Arial", 14, Font.BOLD); var boldTableFont = FontFactory.GetFont("Arial", 12, Font.BOLD); var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC); var bodyFont = FontFactory.GetFont("Arial", 12, Font.NORMAL); document.Add(new Paragraph("Electros LTD", titleFont)); document.Add(new Paragraph("Item:", subTitleFont)); var orderInfoTable = new PdfPTable(5); orderInfoTable.HorizontalAlignment = 0; orderInfoTable.SpacingBefore = 10; orderInfoTable.SpacingAfter = 10; orderInfoTable.DefaultCell.Border = 0; orderInfoTable.SetWidths(new int[] { 3, 4,4,4,4}); orderInfoTable.AddCell("Item No."); orderInfoTable.AddCell("Item:"); orderInfoTable.AddCell("Amount Purchased"); orderInfoTable.AddCell("Date Purchased"); orderInfoTable.AddCell("Warranty Expiry Date"); string id = p.ID.ToString(); id = id.Substring(0, 8); orderInfoTable.AddCell(string.Format("{0}", id)); orderInfoTable.AddCell(string.Format("{0}", p.Name)); orderInfoTable.AddCell(string.Format("{0}", totalAmount)); orderInfoTable.AddCell(string.Format("{0}", order.DateOrdered)); orderInfoTable.AddCell(string.Format("{0}", order.DateOrdered.AddYears(2))); document.Add(orderInfoTable); document.Add(new Paragraph("Fault:",subTitleFont)); var faultInfoTable = new PdfPTable(3); faultInfoTable.HorizontalAlignment = 0; faultInfoTable.SpacingBefore = 10; faultInfoTable.SpacingAfter = 10; faultInfoTable.DefaultCell.Border = 4; faultInfoTable.SetWidths(new int[] { 4, 4, 4 }); //Fault Table faultInfoTable.AddCell("Fault Details"); faultInfoTable.AddCell("Status"); faultInfoTable.AddCell("Date Changed"); foreach (Log l in logs) { faultInfoTable.AddCell(string.Format("{0}",l.Details)); faultInfoTable.AddCell(string.Format("{0}", new WCFFault().GetStatusByID(l.Status).Status1)); faultInfoTable.AddCell(string.Format("{0}", l.Date)); } document.Add(faultInfoTable); // Close the Document - this saves the document contents to the output stream document.Close(); string atch = Server.MapPath("\\Content\\TempReports\\" + fault.Barcode + "Report.pdf"); User user = new WCFUserClient().GetUser(@User.Identity.Name); new WCFBAFuncClient().SendEmailWithAttachment(user.Email, "Product Receipt", "Reciept for the faults of Product " + p.Name + "\nThanks For Using Electros Ltd", atch); return File("/Content/TempReports/"+fault.Barcode+"Report.pdf", "application/pdf"); }
public PartialViewResult ShowUpdateFault(AdminShowFaultModel model) { try { Fault sF = new WCFFaultClient().GetFault(model.FaultID); sF.Details = model.FaultDetails; sF.Status = new Guid(model.faultEntities.Status.ToString()); new WCFFaultClient().UpdateFault(sF); Log l = new Log(); l.ID = Guid.NewGuid(); l.FaultID = sF.ID; l.Details = sF.Details; l.Date = DateTime.Now; l.Status = sF.Status; new WCFFaultClient().AddFaultToLog(l); User user = new WCFUserClient().GetUser(sF.Username); Status s = new WCFFaultClient().GetStatusByID(l.Status); string imgPath = Server.MapPath("\\Content\\Images\\" + sF.Barcode + ".jpg"); // new WCFBAFuncClient().SendEmail(user.Email, "Product Status Change", "Your Product " + sF.Product.Name + " Status Has been changed to " + s.Status1); new WCFBAFuncClient().SendEmailWithAttachment(user.Email, "Product Status Change", "Your Product " + sF.Product.Name + " Status Has been changed to " + s.Status1, imgPath); string errS = SensMsg(user.Mobile, s.Status1, sF.Product.Name); if (errS == "success") { @ViewBag.faultUpdateStatus = "Fault Was Updated Successfully and user was alerted"; return PartialView("_faultUpdated"); } else { @ViewBag.faultUpdateStatus = "Fault Was Updated Successfully and user was alerted but SMS was not sent"; return PartialView("_faultUpdated"); } } catch (Exception) { @ViewBag.faultUpdateStatus="Fault Was Not Updated"; return PartialView("_faultUpdated"); } }