コード例 #1
0
ファイル: Edit.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Printer).State = EntityState.Modified;

            List <PrinterLayerThickness> oldSelection = await _context.PrinterLayerThicknesses.Where(pl => pl.PrinterID == Printer.ID).ToListAsync();

            _context.PrinterLayerThicknesses.RemoveRange(oldSelection);

            foreach (int layerThicknessID in Selected)
            {
                PrinterLayerThickness pl = new PrinterLayerThickness
                {
                    PrinterID        = Printer.ID,
                    LayerThicknessID = layerThicknessID
                };
                _context.PrinterLayerThicknesses.Add(pl);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(PostProcess).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostProcessExists(PostProcess.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            _context.LayerThicknesses.Add(LayerThickness);

            for (int i = 0; i < SelectedPrinters.Count; i++)
            {
                PrinterLayerThickness pl = new PrinterLayerThickness
                {
                    PrinterID        = SelectedPrinters[i],
                    LayerThicknessID = LayerThickness.ID,
                    ExcelDefinedName = DefinedNames[i]
                };
                _context.PrinterLayerThicknesses.Add(pl);
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
ファイル: Edit.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Industry).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Materials.Any(e => e.ID == Industry.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.PostProcesses.Add(PostProcess);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Material).State = EntityState.Modified;

            var postProcessLinks = new List <MaterialPostProcess>();
            // Previously attached post-processes
            List <MaterialPostProcess> selectedPostprocesses = await _context.MaterialPostProcesses.Where(mp => mp.MaterialID == Material.ID).ToListAsync();

            foreach (int postProcessID in PostProcessChecked)
            {
                MaterialPostProcess mp = await _context.MaterialPostProcesses.Where(m => m.MaterialID == Material.ID && m.PostProcessID == postProcessID).FirstOrDefaultAsync();

                if (mp == null)
                {
                    mp = new MaterialPostProcess
                    {
                        MaterialID    = Material.ID,
                        PostProcessID = postProcessID
                    };
                    postProcessLinks.Add(mp);
                }
                selectedPostprocesses.Remove(mp);
            }
            _context.MaterialPostProcesses.AddRange(postProcessLinks);
            _context.MaterialPostProcesses.RemoveRange(selectedPostprocesses);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MaterialExists(Material.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
ファイル: Delete.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Industry = await _context.Industries.FindAsync(id);

            if (Industry != null)
            {
                _context.Industries.Remove(Industry);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #8
0
ファイル: Delete.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PostProcess = await _context.PostProcesses.FindAsync(id);

            if (PostProcess != null)
            {
                _context.PostProcesses.Remove(PostProcess);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #9
0
ファイル: Delete.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Material = await _context.Materials.FindAsync(id);

            if (Material != null)
            {
                _context.Materials.Remove(Material);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #10
0
ファイル: Edit.cshtml.cs プロジェクト: Ahlforn/Portfolio
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            _context.Attach(LayerThickness).State = EntityState.Modified;

            List <PrinterLayerThickness> oldSelection = await _context.PrinterLayerThicknesses.Where(pl => pl.LayerThicknessID == LayerThickness.ID).ToListAsync();

            _context.PrinterLayerThicknesses.RemoveRange(oldSelection);

            //Printers = await _context.Printers.ToListAsync();
            for (int i = 0; i < SelectedPrinters.Count; i++)
            {
                PrinterLayerThickness pl = new PrinterLayerThickness
                {
                    PrinterID        = SelectedPrinters[i],
                    LayerThicknessID = LayerThickness.ID,
                    ExcelDefinedName = DefinedNames[i]
                };
                _context.PrinterLayerThicknesses.Add(pl);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LayerThicknessExists(LayerThickness.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #11
0
ファイル: PrintModelUpload.cs プロジェクト: Ahlforn/Portfolio
        public async Task AddToDb(string filepath, SiteContext context, SiteUser user, int?orderID)
        {
            FileInfo   file  = new FileInfo(filepath);
            PrintModel model = new PrintModel();

            model.Name        = this.Name;
            model.Description = this.Description;
            model.Filename    = file.Name;
            model.UploadDate  = DateTime.Now;

            try
            {
                PrintModelFile printModelFile = new PrintModelFile(filepath, PrintModelFile.FileType.STL);

                model.X      = printModelFile.X;
                model.Y      = printModelFile.Y;
                model.Z      = printModelFile.Z;
                model.Volume = printModelFile.Volume;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (orderID == null)
            {
                throw new Exception("No quotation ID provided");
            }

            Quotation quotation = await context.Quotations.Include(q => q.PrintModels).FirstOrDefaultAsync(q => q.ID == orderID);

            quotation.PrintModels.Add(model);
            context.Quotations.Update(quotation);

            model.User      = user;
            model.Quotation = quotation;

            context.PrintModels.Add(model);
            await context.SaveChangesAsync();
        }