예제 #1
0
 public async Task <IActionResult> OnPostAsync(int?id)
 {
     if (id == null)
     {
         return(NotFound());
     }
     try
     {
         if (await _context.Visit.AnyAsync(
                 m => m.ID == id))
         {
             // Department.rowVersion value is from when the entity
             // was fetched. If it doesn't match the DB, a
             // DbUpdateConcurrencyException exception is thrown.
             _context.Visit.Remove(Visit);
             await _context.SaveChangesAsync();
         }
         return(RedirectToPage("./Index"));
     }
     catch (DbUpdateConcurrencyException)
     {
         return(RedirectToPage("./Delete",
                               new { concurrencyError = true, id = id }));
     }
 }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var repToDelete = await _context.Repair.Include(r => r.Car).FirstAsync(r => r.RepairID == id);

            _context.Entry(repToDelete)
            .Property("RowVersion").OriginalValue = Repair.RowVersion;
            _context.Entry(repToDelete.Car)
            .Property("RowVersion").OriginalValue = Repair.Car.RowVersion;
            try
            {
                if (repToDelete != null)
                {
                    if (repToDelete.Car != null)
                    {
                        _context.Car.Remove(repToDelete.Car);
                    }
                    _context.Repair.Remove(repToDelete);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(RedirectToPage("./Delete",
                                      new { concurrencyError = true, id = id }));
            }
        }
예제 #3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Visit emptyVisit = new Visit();

            if (await TryUpdateModelAsync <Visit>(emptyVisit, "Visit",
                                                  v => v.VisitPurpose, v => v.PlannedVisitDate
                                                  ))
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(NotFound());
                }

                emptyVisit.VisitClient    = user;
                emptyVisit.AcceptedClient = true;
                _context.Visit.Add(emptyVisit);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Invoice.Add(Invoice);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            try
            {
                if (await _context.ReplacedPart.AnyAsync(
                        m => m.ReplacedPartID == id))
                {
                    _context.ReplacedPart.Remove(ReplacedPart);
                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                return(RedirectToPage("./Delete",
                                      new { concurrencyError = true, id = id }));
            }

            if (ReplacedPart.OldPartImage != null)
            {
                var imagePath = Path.Combine(_hostEnviroment.WebRootPath, "imgs/oldparts", ReplacedPart.OldPartImage.FileName);
                if (System.IO.File.Exists(imagePath))
                {
                    System.IO.File.Delete(imagePath);
                    _context.Files.Remove(ReplacedPart.OldPartImage);
                }
            }

            if (ReplacedPart.NewPartBill != null)
            {
                var billPath = Path.Combine(_hostEnviroment.WebRootPath, "bills", ReplacedPart.NewPartBill.FileName);
                if (System.IO.File.Exists(billPath))
                {
                    System.IO.File.Delete(billPath);
                    _context.Files.Remove(ReplacedPart.NewPartBill);
                }
            }



            return(RedirectToPage("/Repairs/Index", "id", new { id = ReplacedPart.RepairID }));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            Repair repair = await _context.Repair
                            .Include(r => r.Client)
                            .FirstOrDefaultAsync(r => r.RepairID == InvoiceModel.RepairID);

            if (repair == null)
            {
                return(NotFound());
            }

            var u = await _userManager.GetUserAsync(User);

            var seqNum = _context.GetNextDocVal();

            string newNumber = "FA" + seqNum.ToString("D5") + "/" + DateTime.Now.ToString("yyyy-MM-dd");

            _logger.LogInformation("INVOICE TO REPAIR " + repair.RepairID);
            Invoice emptyInvoice = new Invoice
            {
                RepairID      = repair.RepairID,
                createdDate   = InvoiceModel.issueDate,
                Sum           = InvoiceModel.Sum,
                IssuedBy      = u,
                InvoiceNumber = newNumber,
                IssuedTo      = repair.Client
            };

            _context.Invoice.Add(emptyInvoice);
            repair.InvoiceIssued = true;

            var result = await _context.SaveChangesAsync();

            return(RedirectToPage("/Repairs/Index"));
        }
예제 #7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var emptyCar = new Car();

            if (await TryUpdateModelAsync <Car>(emptyCar, "Car",
                                                s => s.Brand, s => s.Model, s => s.productionYear, s => s.EngineCapacity, s => s.EngineFuel, s => s.oilChangeDate, s => s.BodyType))
            {
                _context.Car.Add(emptyCar);
            }
            else
            {
                return(Page());
            }

            var emptyRepair = new Repair();

            if (await TryUpdateModelAsync <Repair>(emptyRepair, "Repair",
                                                   s => s.Description, s => s.startTime, s => s.WorkPrice, s => s.ClientID, s => s.ProblemDescription, s => s.RepairState, s => s.ChangeOil))
            {
                emptyRepair.Car = emptyCar;
                ClaimsPrincipal currentUser = this.User;
                emptyRepair.AssignedMechanic = await _userManager.GetUserAsync(currentUser);

                _context.Repair.Add(emptyRepair);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            initializeSelectList(_context);
            return(Page());
        }
예제 #8
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            var repairToUpdate = await _context.Repair.FindAsync(id);

            if (repairToUpdate == null)
            {
                return(NotFound());
            }

            _context.Entry(repairToUpdate)
            .Property("RowVersion").OriginalValue = Repair.RowVersion;

            if (await TryUpdateModelAsync <Repair>(repairToUpdate, "Repair",
                                                   s => s.Description, s => s.startTime, s => s.WorkPrice, s => s.ClientID, s => s.ProblemDescription, s => s.RepairState, s => s.ChangeOil))
            {
                _logger.LogInformation(repairToUpdate.CarID.ToString());
                var carToUpdate = await _context.Car.FindAsync(repairToUpdate.CarID);


                _context.Entry(carToUpdate)
                .Property("RowVersion").OriginalValue = Repair.Car.RowVersion;

                if (await TryUpdateModelAsync <Car>(carToUpdate, "Repair.Car",
                                                    s => s.Brand, s => s.Model, s => s.productionYear, s => s.EngineCapacity, s => s.EngineFuel, s => s.oilChangeDate, s => s.BodyType))
                {
                    /*
                     * carToUpdate.Brand = Repair.Car.Brand;
                     * carToUpdate.Model = Repair.Car.Model;
                     * carToUpdate.productionYear = Repair.Car.productionYear;
                     * carToUpdate.EngineCapacity = Repair.Car.EngineCapacity;
                     * carToUpdate.EngineFuel = Repair.Car.EngineFuel;
                     * carToUpdate.oilChangeDate = Repair.Car.oilChangeDate;
                     * carToUpdate.BodyType = Repair.Car.BodyType;
                     */
                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var exceptionEntry = ex.Entries.Single();
                        var databaseEntry  = exceptionEntry.GetDatabaseValues();
                        if (databaseEntry == null)
                        {
                            ModelState.AddModelError(string.Empty, "Unable to save. " +
                                                     "The repair was deleted by another user.");
                            return(Page());
                        }

                        var dbValues = databaseEntry.ToObject();
                        ModelState.AddModelError(string.Empty,
                                                 "The Repair you attempted to edit "
                                                 + "was modified by another user after you. The "
                                                 + "edit operation was canceled and the current values in the database "
                                                 + "have been displayed. If you still want to edit this record, click "
                                                 + "the Save button again.");
                        // Save the current RowVersion so next postback
                        // matches unless an new concurrency issue happens.
                        if (dbValues.GetType().Equals(typeof(Repair)))
                        {
                            var rep = (Repair)dbValues;
                            Repair.RowVersion = (byte[])rep.RowVersion;
                            ModelState.Remove("Repair.RowVersion");
                        }
                        else
                        {
                            var car = (Car)dbValues;
                            Repair.Car.RowVersion = (byte[])car.RowVersion;
                            ModelState.Remove("Repair.Car.RowVersion");
                        }



                        return(Page());

                        /*
                         * if (!RepairExists(Repair.RepairID))
                         * {
                         *  return NotFound();
                         * }
                         *
                         *
                         * if (!CarExists(Repair.Car.CarID))
                         * {
                         *  return NotFound();
                         * }
                         * throw;*/
                    }
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #9
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyPart = new ReplacedPart();

            if (await TryUpdateModelAsync <ReplacedPart>(emptyPart, "ReplacedPart",
                                                         p => p.Name, p => p.Manufacturer, p => p.ProductionDate, p => p.Quantity, p => p.Price))
            {
                var repair = await _context.Repair.FindAsync(id);

                if (repair == null || repair.InvoiceIssued)
                {
                    return(NotFound());
                }
                emptyPart.Repair = repair;

                string wwwRoot = _hostEnviroment.WebRootPath;


                if (ReplacedPart.NewPartBill != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.NewPartBill.File.FileName);
                    ReplacedPart.NewPartBill.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/bills/", ReplacedPart.NewPartBill.FileName);

                    var billModel = new FileModel
                    {
                        Title    = ReplacedPart.NewPartBill.Title,
                        FileName = ReplacedPart.NewPartBill.FileName
                    };

                    using (var fileSteam = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.NewPartBill.File.CopyToAsync(fileSteam);
                    }

                    _context.Files.Add(billModel);
                    emptyPart.NewPartBill = billModel;
                }

                if (ReplacedPart.OldPartImage.File != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.OldPartImage.File.FileName);
                    ReplacedPart.OldPartImage.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/imgs/oldparts/", ReplacedPart.OldPartImage.FileName);

                    var image = new FileModel
                    {
                        Title    = ReplacedPart.OldPartImage.Title,
                        FileName = ReplacedPart.OldPartImage.FileName
                    };

                    using (var fileSteam = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.OldPartImage.File.CopyToAsync(fileSteam);
                    }

                    _context.Files.Add(image);
                    emptyPart.OldPartImage = image;
                }

                _context.ReplacedPart.Add(emptyPart);
                await _context.SaveChangesAsync();
            }



            //return RedirectToPage("/Repairs/Index");
            return(RedirectToPage("/Repairs/Index", "id", new { id = id }));
        }
예제 #10
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var partToUpdate = await _context.ReplacedPart
                               .Include(rp => rp.OldPartImage)
                               .Include(rp => rp.NewPartBill)
                               .FirstOrDefaultAsync(rp => rp.ReplacedPartID == id.Value);

            if (partToUpdate == null)
            {
                return(NotFound());
            }

            _context.Entry(partToUpdate)
            .Property("RowVersion").OriginalValue = ReplacedPart.RowVersion;

            if (await TryUpdateModelAsync <ReplacedPart>(partToUpdate, "ReplacedPart",
                                                         p => p.Name, p => p.Manufacturer, p => p.ProductionDate, p => p.Quantity, p => p.Price))
            {
                string wwwRoot = _hostEnviroment.WebRootPath;
                if (ReplacedPart.OldPartImage.File != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.OldPartImage.File.FileName);
                    ReplacedPart.OldPartImage.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/imgs/oldparts/", ReplacedPart.OldPartImage.FileName);

                    if (partToUpdate.OldPartImage != null)
                    {
                        var imagePath = Path.Combine(wwwRoot, "imgs/oldparts", partToUpdate.OldPartImage.FileName);
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                            partToUpdate.OldPartImage.FileName = ReplacedPart.OldPartImage.FileName;
                            partToUpdate.OldPartImage.Title    = ReplacedPart.OldPartImage.Title;
                        }
                    }
                    else
                    {
                        var image = new FileModel
                        {
                            Title    = ReplacedPart.OldPartImage.Title,
                            FileName = ReplacedPart.OldPartImage.FileName
                        };
                        _context.Files.Add(image);
                        partToUpdate.OldPartImage = image;
                    }


                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.OldPartImage.File.CopyToAsync(fileStream);
                    }
                }

                if (ReplacedPart.NewPartBill != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.NewPartBill.File.FileName);
                    ReplacedPart.NewPartBill.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/bills/", ReplacedPart.NewPartBill.FileName);

                    if (partToUpdate.NewPartBill != null)
                    {
                        var imagePath = Path.Combine(wwwRoot, "bills", partToUpdate.NewPartBill.FileName);
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                            partToUpdate.NewPartBill.FileName = ReplacedPart.NewPartBill.FileName;
                            partToUpdate.NewPartBill.Title    = ReplacedPart.NewPartBill.Title;
                        }
                    }
                    else
                    {
                        var billModel = new FileModel
                        {
                            Title    = ReplacedPart.NewPartBill.Title,
                            FileName = ReplacedPart.NewPartBill.FileName
                        };
                        _context.Files.Add(billModel);
                        partToUpdate.NewPartBill = billModel;
                    }


                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.NewPartBill.File.CopyToAsync(fileStream);
                    }
                }


                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty, "Unable to save. " +
                                                 "The replaced part was deleted by another user.");
                        return(Page());
                    }

                    var dbValues = (ReplacedPart)databaseEntry.ToObject();
                    ModelState.AddModelError(string.Empty,
                                             "The Replaced Part you attempted to edit "
                                             + "was modified by another user after you. The "
                                             + "edit operation was canceled and the current values in the database "
                                             + "have been displayed. If you still want to edit this part, click "
                                             + "the Save button again.");


                    ReplacedPart.RowVersion = (byte[])dbValues.RowVersion;
                    // Clear the model error for the next postback.
                    ModelState.Remove("ReplacedPart.RowVersion");

                    return(Page());
                }
            }
            return(RedirectToPage("/Repairs/Index", "id", new { id = partToUpdate.RepairID }));
        }
예제 #11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var visitToUpdate = await _context.Visit.FindAsync(id);

            if (visitToUpdate == null)
            {
                return(NotFound());
            }

            var acceptedDate = visitToUpdate.PlannedVisitDate;



            _context.Entry(visitToUpdate)
            .Property("RowVersion").OriginalValue = Visit.RowVersion;
            if (await TryUpdateModelAsync <Visit>(visitToUpdate, "Visit"
                                                  , s => s.PlannedVisitDate, s => s.AcceptedClient, s => s.AcceptedMechanic, s => s.VisitMechanicID, s => s.VisitPurpose))
            {
                if (DateTime.Compare(acceptedDate, visitToUpdate.PlannedVisitDate) != 0)
                {
                    if (User.IsInRole("Mechanic"))
                    {
                        visitToUpdate.AcceptedClient = false;
                    }
                    else
                    {
                        visitToUpdate.AcceptedMechanic = false;
                    }
                }


                try
                {
                    await _context.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty, "Unable to save. " +
                                                 "The visit was canceled by another user.");
                        return(Page());
                    }

                    var dbValues = (Visit)databaseEntry.ToObject();
                    ModelState.AddModelError(string.Empty,
                                             "The Visit you attempted to edit "
                                             + "was modified by another user after you. The "
                                             + "edit operation was canceled and the current values in the database "
                                             + "have been displayed. If you still want to edit this visit, click "
                                             + "the Save button again.");


                    Visit.RowVersion = (byte[])dbValues.RowVersion;
                    // Clear the model error for the next postback.
                    ModelState.Remove("Visit.RowVersion");

                    return(Page());
                }
            }


            return(RedirectToPage("./Index"));
        }