Пример #1
0
        public async Task <ActionResult> Create(ApplicantViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (Session["@Tracker"] is Guid existingTracker)
            {
                var existingApplicant = await _context.Applicant.FirstOrDefaultAsync(it => it.Tracker == existingTracker);

                _mapper.Map(viewModel, existingApplicant);

                _context.Entry(existingApplicant).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(RedirectToAction("Create", "Address"));
            }

            var tracker = Guid.NewGuid();

            Session["@Tracker"] = tracker;

            var applicant = _mapper.Map <Applicant>(viewModel);

            applicant.Tracker = tracker;

            _context.Applicant.Add(applicant);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Create", "Address"));
        }
Пример #2
0
        public async Task <ActionResult> Create(ProductViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tracker = (Guid)Session["@Tracker"];

            var applicant = await _context.Applicant.FirstOrDefaultAsync(it => it.Tracker == tracker);

            var existingProduct = await _context.Products.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker);

            if (existingProduct != null)
            {
                _mapper.Map(viewModel, existingProduct);
                _context.Entry(existingProduct).State = EntityState.Modified;
            }
            else
            {
                var product = _mapper.Map <Product>(viewModel);
                product.Applicant = applicant;
                _context.Products.Add(product);
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Final"));
        }
Пример #3
0
        public async Task <ActionResult> Create(VehicleViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tracker = (Guid)Session["@Tracker"];

            var applicant = await _context.Applicant.FirstOrDefaultAsync(it => it.Tracker == tracker);

            var existingVehicle = await _context.Vehicles.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker);

            if (existingVehicle != null)
            {
                _mapper.Map(viewModel, existingVehicle);
                _context.Entry(existingVehicle).State = EntityState.Modified;
            }
            else
            {
                var vehicle = _mapper.Map <Vehicle>(viewModel);
                vehicle.Applicant = applicant;
                _context.Vehicles.Add(vehicle);
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Create", "Product"));
        }
Пример #4
0
        public async Task <ActionResult> Create(AddressesViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tracker = (Guid)Session["@Tracker"];

            var applicant = await _context.Applicant.FirstOrDefaultAsync(it => it.Tracker == tracker);

            var existingMain = await _context.Addresses.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker && !it.IsMailing);

            if (existingMain != null)
            {
                _mapper.Map(viewModel.Main, existingMain);
                _context.Entry(existingMain).State = EntityState.Modified;
            }
            else
            {
                var main = _mapper.Map <Address>(viewModel.Main);
                main.Applicant = applicant;
                main.IsMailing = false;
                _context.Addresses.Add(main);
            }

            var existingMailing = await _context.Addresses.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker && it.IsMailing);

            if (existingMailing != null)
            {
                _mapper.Map(viewModel.Mailing, existingMailing);
                _context.Entry(existingMailing).State = EntityState.Modified;
            }
            else
            {
                var mailing = _mapper.Map <Address>(viewModel.Mailing);
                mailing.Applicant = applicant;
                mailing.IsMailing = true;
                _context.Addresses.Add(mailing);
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Create", "Employment"));
        }
Пример #5
0
        public async Task <ActionResult> Create(EmploymentsViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tracker = (Guid)Session["@Tracker"];

            var applicant = await _context.Applicant.FirstOrDefaultAsync(it => it.Tracker == tracker);

            var existingPrimary = await _context.Employements.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker && it.IsPrimary);

            if (existingPrimary != null)
            {
                _mapper.Map(viewModel.Primary, existingPrimary);
                _context.Entry(existingPrimary).State = EntityState.Modified;
            }
            else
            {
                var primary = _mapper.Map <Employement>(viewModel.Primary);
                primary.Applicant = applicant;
                primary.IsPrimary = true;
                _context.Employements.Add(primary);
            }

            var existingPrevious = await _context.Employements.FirstOrDefaultAsync(it => it.Applicant.Tracker == tracker && !it.IsPrimary);

            if (existingPrevious != null)
            {
                _mapper.Map(viewModel.Previous, existingPrevious);
                _context.Entry(existingPrevious).State = EntityState.Modified;
            }
            else
            {
                var previous = _mapper.Map <Employement>(viewModel.Previous);
                previous.Applicant = applicant;
                previous.IsPrimary = false;
                _context.Employements.Add(previous);
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Create", "Vehicle"));
        }