public ActionResult Create(string uuid) { Session["alreadyCreatedId"] = null; //Check if Productsheet already exists and redirect to it ProductSheet UuidExists = _dbContext.ProductSheet.FirstOrDefault(ps => ps.Uuid == uuid); if (UuidExists != null && !string.IsNullOrWhiteSpace(uuid)) { return(RedirectToAction("Edit", new { id = UuidExists.Id })); } ProductSheet model = null; if (!string.IsNullOrWhiteSpace(uuid)) { model = _productSheetService.CreateProductSheetFromMetadata(uuid); } else { model = new ProductSheet(); } ViewBag.MaintenanceFrequencyValues = new SelectList(GetCodeList("9A46038D-16EE-4562-96D2-8F6304AAB124"), "Key", "Value", model.MaintenanceFrequency); return(View(model)); }
public ActionResult CreatePdf(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var imagePath = Server.MapPath("~/Images/"); var imagePathLogo = Server.MapPath("~/Logos/"); ProductSheet productSheet = _dbContext.ProductSheet.Find(id); if (productSheet == null) { return(HttpNotFound()); } string logoPath = ""; //Logo logo =_productSheetService.FindLogoForOrganization(ClaimsPrincipal.Current.Organization()); string logo = _productSheetService.GetLogoForOrganization(productSheet.ContactOwner.Organization); if (logo != null) { logoPath = logo; } Stream fileStream = new PdfGenerator(productSheet, imagePath, logoPath).CreatePdf(); var fileStreamResult = new FileStreamResult(fileStream, "application/pdf"); fileStreamResult.FileDownloadName = GetSafeFilename(productSheet.Title + ".pdf"); Log.Info(string.Format("Creating PDF for {0} [{1}]", productSheet.Title, productSheet.Uuid)); return(fileStreamResult); }
// GET: ProductSheets/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductSheet productSheet = _dbContext.ProductSheet.Find(id); if (productSheet == null) { return(HttpNotFound()); } return(View(productSheet)); }
public ActionResult DeleteConfirmed(int id) { ProductSheet productSheet = _dbContext.ProductSheet.Find(id); if (ClaimsPrincipal.Current.GetOrganizationName().ToLower() == productSheet.ContactMetadata.Organization.ToLower() || IsAdmin()) { _dbContext.ProductSheet.Remove(productSheet); _dbContext.SaveChanges(); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(RedirectToAction("Index")); }
// GET: ProductSheets/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("Index")); } ProductSheet productSheet = _dbContext.ProductSheet.Find(id); if (productSheet == null) { return(HttpNotFound()); } ViewBag.MaintenanceFrequencyValues = new SelectList(GetCodeList("9A46038D-16EE-4562-96D2-8F6304AAB124"), "Key", "Value", productSheet.MaintenanceFrequency); return(View(productSheet)); }
public ActionResult Create(ProductSheet productSheet) { if (ModelState.IsValid) { if (Session["alreadyCreatedId"] != null) { productSheet.Id = (int)Session["alreadyCreatedId"]; _dbContext.Entry(productSheet).State = EntityState.Modified; } else { _dbContext.ProductSheet.Add(productSheet); } _dbContext.SaveChanges(); Session["alreadyCreatedId"] = productSheet.Id; return(RedirectToAction("CreatePdf", new { id = productSheet.Id })); } return(View("Edit", productSheet)); }
public ActionResult Edit(ProductSheet productSheet) { if (!string.IsNullOrWhiteSpace(Request["hentNyeMetaData"])) { ProductSheet model = _dbContext.ProductSheet.Find(productSheet.Id); if (model == null) { return(HttpNotFound()); } model = _productSheetService.UpdateProductSheetFromMetadata(productSheet.Uuid, model); model.PrecisionInMeters = productSheet.PrecisionInMeters; model.ServiceDetails = productSheet.ServiceDetails; model.ListOfFeatureTypes = productSheet.ListOfFeatureTypes; model.ListOfAttributes = productSheet.ListOfAttributes; if (ModelState.IsValid) { _dbContext.Entry(model).State = EntityState.Modified; _dbContext.SaveChanges(); } return(RedirectToAction("Edit", new { id = model.Id })); } else { if (ModelState.IsValid) { _dbContext.Entry(productSheet).State = EntityState.Modified; _dbContext.SaveChanges(); return(RedirectToAction("CreatePdf", new { id = productSheet.Id })); } return(View(productSheet)); } }
public async Task OnHandle(string handle, params object[] argument) { switch (handle) { case "AddProductSheet": { var kvp = this.SheetByWorksheet.FirstOrDefault(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is ProductSheet); ProductSheet productSheet; if (kvp.Value == null) { var iWorksheet = this.ActiveWorkbook.AddWorksheet(0); iWorksheet.Name = "Products"; productSheet = new ProductSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, productSheet); } else { productSheet = (ProductSheet)this.SheetByWorksheet[kvp.Key]; } await productSheet.Refresh().ConfigureAwait(false); productSheet.Sheet.IsActive = true; } break; case "ListCovid19Sheet": { var kvp = this.SheetByWorksheet.FirstOrDefault(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is Covid19Sheet); Covid19Sheet covid19Sheet = null; if (kvp.Value == null) { var ws = this.ActiveWorkbook.AddWorksheet(0); ws.Name = "Covid19"; covid19Sheet = new Covid19Sheet(this, ws); this.SheetByWorksheet.Add(ws, covid19Sheet); } else { covid19Sheet = (Covid19Sheet)this.SheetByWorksheet[kvp.Key]; } await covid19Sheet.Refresh().ConfigureAwait(false); covid19Sheet.Sheet.IsActive = true; } break; case "AddDemoSheet": { var wsCount = this.SheetByWorksheet.Count(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is DemoSheet); var iWorksheet = this.ActiveWorkbook.AddWorksheet(0); iWorksheet.Name = $"Demo {wsCount}"; var demoSheet = new DemoSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, demoSheet); await demoSheet.Refresh().ConfigureAwait(false); demoSheet.Sheet.IsActive = true; } break; case "InvoicesSheet": { var kvp = this.SheetByWorksheet.FirstOrDefault(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is InvoicesSheet); InvoicesSheet invoicesSheet; if (kvp.Value == null) { var iWorksheet = this.ActiveWorkbook.AddWorksheet(0); iWorksheet.Name = KnownNames.InvoicesSheetName; invoicesSheet = new InvoicesSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, invoicesSheet); } else { invoicesSheet = (InvoicesSheet)this.SheetByWorksheet[kvp.Key]; } await invoicesSheet.Refresh().ConfigureAwait(false); invoicesSheet.Sheet.IsActive = true; } break; case "AddInvoiceSheet": { var wsCount = this.Services.Database.Count <Invoice>(); var iWorksheet = this.ActiveWorksheet; var invoiceSheet = new InvoiceSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, invoiceSheet); await invoiceSheet.Refresh().ConfigureAwait(false); //invoiceSheet.Sheet.IsActive = true; } break; case "InsertPicture": { if (this.SheetByWorksheet.TryGetValue(this.ActiveWorksheet, out var iSheet)) { if (iSheet is DemoSheet demoSheet) { demoSheet.InsertPicture(); } } } break; case "SaveInvoiceSheet": { if (this.SheetByWorksheet.TryGetValue(this.ActiveWorksheet, out var iSheet)) { if (iSheet is InvoiceSheet invoiceSheet) { await invoiceSheet.Save(); } } foreach (ISheet sheet in this.SheetByWorksheet.Where(v => v.Value is InvoicesSheet).Select(v => v.Value)) { sheet.IsWorksheetUpToDate = false; } } break; case "SaveOrganisationsSheet": { if (this.SheetByWorksheet.TryGetValue(this.ActiveWorksheet, out var iSheet)) { if (iSheet is OrganisationsSheet organisationsSheet) { await organisationsSheet.Save(); } } foreach (ISheet sheet in this.SheetByWorksheet.Where(v => v.Value is OrganisationsSheet).Select(v => v.Value)) { sheet.IsWorksheetUpToDate = false; } } break; case "SaveAsPDFInvoiceSheet": { if (this.SheetByWorksheet.TryGetValue(this.ActiveWorksheet, out var iSheet)) { if (iSheet is InvoiceSheet invoiceSheet) { invoiceSheet.SaveAsPDF(); } } } break; case "OrganisationsSheet": { var kvp = this.SheetByWorksheet.FirstOrDefault(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is OrganisationsSheet); OrganisationsSheet organisationsSheet; if (kvp.Value == null) { var iWorksheet = this.ActiveWorkbook.AddWorksheet(0); iWorksheet.Name = "Organisations"; organisationsSheet = new OrganisationsSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, organisationsSheet); } else { organisationsSheet = (OrganisationsSheet)this.SheetByWorksheet[kvp.Key]; } await organisationsSheet.Refresh().ConfigureAwait(false); organisationsSheet.Sheet.IsActive = true; } break; case "PaymentTermsSheet": { var kvp = this.SheetByWorksheet.FirstOrDefault(v => Equals(v.Key.Workbook, this.ActiveWorkbook) && v.Value is PaymentTermsSheet); PaymentTermsSheet paymentTermsSheet; if (kvp.Value == null) { var iWorksheet = this.ActiveWorkbook.AddWorksheet(0); iWorksheet.Name = KnownNames.PaymentTermsSheetName; paymentTermsSheet = new PaymentTermsSheet(this, iWorksheet); this.SheetByWorksheet.Add(iWorksheet, paymentTermsSheet); } else { paymentTermsSheet = (PaymentTermsSheet)this.SheetByWorksheet[kvp.Key]; } await paymentTermsSheet.Refresh().ConfigureAwait(false); paymentTermsSheet.Sheet.IsActive = true; } break; } }
public ActionResult Index() { return(View(ProductSheet.GetData())); }