Example #1
0
        public async Task <IActionResult> CreateFromFind(string vin, string bodyNumber, string frameNumber, string regNumber)
        {
            var card = new DiagnosticCard
            {
                VIN         = vin,
                BodyNumber  = bodyNumber,
                FrameNumber = frameNumber,
                RegNumber   = regNumber
            };

            CreateOrEditInit();
            return(View("Create", card));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,Id,CardId,Lastname,Firstname,Patronymic,VIN,IssueYear,Manufacturer,Model,BodyNumber,FrameNumber,Running,RegNumber,Weight,Category,CategoryCommon,TyreManufacturer,AllowedMaxWeight,FuelType,BrakeType,DocumentType,IsForeigner,DocumentSeries,DocumentNumber,DocumentIssueDate,DocumentIssuer,Note,ExpirationDate,CardType,CreatedDate")] DiagnosticCard diagnosticCard, bool register = false)
        {
            CreateOrEditInit();
            if (id != diagnosticCard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(diagnosticCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiagnosticCardExists(diagnosticCard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (!register)
                {
                    return(RedirectToAction("Index"));
                }
                try
                {
                    await RegisterCard(diagnosticCard.Id);

                    return(RedirectToAction("Index"));
                }
                catch (RegisterCardException e)
                {
                    this.AddErrorMessage(e.Message);
                    this.AddInfoMessage("Изменения сохранены. Вы можете попытаться отправить карту на регистрацию еще раз несколько позже.");
                    return(RedirectToAction("Edit", new { id = diagnosticCard.Id }));
                }
                catch (NotAuthorizedException)
                {
                    return(await Logout());
                }
            }
            return(View(diagnosticCard));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("UserId,Lastname,Firstname,Patronymic,VIN,IssueYear,Manufacturer,Model,BodyNumber,FrameNumber,Running,RegNumber,Weight,Category,CategoryCommon,TyreManufacturer,AllowedMaxWeight,FuelType,BrakeType,DocumentType,IsForeigner,DocumentSeries,DocumentNumber,DocumentIssueDate,DocumentIssuer,Note,ExpirationDate,CardType")] DiagnosticCard diagnosticCard, bool register = false)
        {
            if (ModelState.IsValid)
            {
                //diagnosticCard.Id = 0;
                diagnosticCard.UserId = _userManager.GetUserId(User);
                //diagnosticCard.CardId = null;
                //diagnosticCard.RegisteredDate = null;
                diagnosticCard.CreatedDate = DateTime.UtcNow.AddHours(3); // Moscow time
                //diagnosticCard.VIN = diagnosticCard.VIN?.ToUpper();
                _context.Add(diagnosticCard);
                await _context.SaveChangesAsync();

                if (!register)
                {
                    this.AddInfoMessage("Изменения сохранены");
                    return(RedirectToAction("Index"));
                }
                try
                {
                    await RegisterCard(diagnosticCard.Id);

                    return(RedirectToAction("Index"));
                }
                catch (RegisterCardException e)
                {
                    this.AddErrorMessage(e.Message);
                    this.AddInfoMessage("Карта сохранена как черновик. Вы можете попытаться отправить ее на регистрацию еще раз несколько позже.");
                    return(RedirectToAction("Edit", new { id = diagnosticCard.Id }));
                }
                catch (NotAuthorizedException)
                {
                    this.AddInfoMessage("Карта сохранена как черновик.");
                    return(await Logout(Url.Action("Edit", new { id = diagnosticCard.Id })));
                }
            }

            CreateOrEditInit();
            return(View(diagnosticCard));
        }