public IActionResult AddClaimFile(InsuranceClaimsAddClaimFileViewModel model)
        {
            InsuranceClaim insuranceClaim = _insuranceClaimsRepository.GetClaim(model.Id);

            if (ModelState.IsValid)
            {
                FileHandler     fileHandler     = new FileHandler();
                FileDescription fileDescription = fileHandler.UploadSingleFile(model.File, model.FileType, insuranceClaim.ClaimNo, DateTime.Now, model.Descrption);
                _fileDescriptionsRepository.Create(fileDescription);
                InsuranceClaimFile claimFile = new InsuranceClaimFile
                {
                    FileDescriptionId = fileDescription.Id,
                    InsuranceClaimId  = insuranceClaim.Id
                };
                _insuranceClaimFilesRepository.Add(claimFile);
                insuranceClaim.InsuranceClaimFiles.Add(claimFile);
                _insuranceClaimsRepository.Update(insuranceClaim);
                return(RedirectToAction("details", new { id = model.Id }));
            }
            return(RedirectToAction("AddClaimFile", new { id = model.Id }));
        }
Ejemplo n.º 2
0
        public IActionResult AddService(AddServiceViewModel model)
        {
            if (ModelState.IsValid)
            {
                Car     car     = _carsrepository.GetCar(model.CarId);
                Service service = new Service
                {
                    CarId       = model.CarId,
                    ClientId    = model.ServiceFacilityId,
                    Milage      = model.Milage,
                    Date        = model.Date,
                    ServiceType = model.ServiceType,
                    Cost        = model.Cost,
                    Id          = new Guid()
                };
                MilageRecord record = new MilageRecord
                {
                    CarId  = service.CarId,
                    Date   = service.Date,
                    Milage = service.Milage,
                    Id     = Guid.NewGuid()
                };
                _milageRecordsRepository.Add(record);
                Guid fileid = Guid.Empty;
                if (model.IsInvoiceAdded)
                {
                    FileHandler     fileHandler     = new FileHandler();
                    FileDescription fileDescription = fileHandler.UploadSingleFile(model.File, FileType.Serwis, car.RegistrationNumber, model.Date);
                    _fileDescriptionsRepository.Create(fileDescription);
                    Invoice invoice = new Invoice
                    {
                        Id                = Guid.NewGuid(),
                        Number            = model.Number,
                        Date              = model.Date,
                        Amount            = model.Cost,
                        ClientId          = model.ServiceFacilityId,
                        InvoiceType       = InvoiceType.Koszt,
                        FileDescriptionId = fileDescription.Id
                    };
                    _invoicesRepository.Add(invoice);
                    service.InvoiceId = invoice.Id;
                    fileid            = fileDescription.Id;
                }

                car.Milage            = model.Milage;
                car.NextServiceMilage = model.Milage + car.ServiceInterval;
                _carsrepository.Update(car);
                _sevicesRepository.Add(service);
                if (model.IsInvoiceAdded)
                {
                    ServiceFile serviceFile = new ServiceFile
                    {
                        ServiceId         = service.Id,
                        FileDescriptionId = fileid
                    };
                    _serviceFilesRepository.Add(serviceFile);
                }
                return(RedirectToAction("details", "cars", new { id = model.CarId }));
            }
            return(RedirectToAction("addservice", "services", new { id = model.CarId }));
        }