Ejemplo n.º 1
0
        public ActionResult Create(ProposalViewModel proposal)
        {
            Lecturer lecturer = _lecturerctx.GetLecturer(User.Identity.Name.ToString().Substring(1, User.Identity.Name.Length - 1));

            if (ModelState.IsValid)
            {
                proposal.SubmittedDate = DateTime.Now;
                _proposalctx.AddProposal(proposal, lecturer.lecturer_id, lecturer.course_id);
                _proposalctx.ApproveProposal(proposal.Id);
                return(RedirectToAction("Index"));
            }

            return(View("~/Views/_Lecturer/Proposal/Create.cshtml", proposal));
        }
 public int AddProposal(DemoDotnetCoreApp.Models.Proposal proposal)
 {
     return(_iProposalRepository.AddProposal(_mapper.Map <DemoDotnetCoreApp.Data.Proposal>(proposal)));
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreateViewModel viewModel, string connectionId, bool more)
        {
            //Добавление элемента в базу
            try
            {
                // Проверка количества загруженных фото
                if (viewModel.Images != null && viewModel.Images.Count > 7)
                {
                    ModelState.AddModelError("", "Максимальное кол-во фото в предложении - 7 шт.");
                }

                //Проверка введенных данных
                if (ModelState.IsValid)
                {
                    // Добавление станка при отсутствии в базе
                    var machine = await _machineRepository.GetMachine(viewModel.Machine);

                    if (machine == null)
                    {
                        machine = await _machineRepository.AddMachine(viewModel.Machine, await _machineTypeRepository.AddMachineType("Без группы"));
                    }

                    // Добавляемый элемент
                    var proposal = new Proposal
                    {
                        UserName      = User.Identity.Name,
                        CreateDate    = DateTime.Now,
                        Location      = viewModel.Location,
                        MachineId     = machine.Id,
                        PurshasePrice = (int)viewModel.PurshasePrice,
                        SellingPrice  = (int)viewModel.SellingPrice,
                        Comment       = viewModel.Comment
                    };

                    await _proposalRepository.AddProposal(proposal);

                    try
                    {
                        await _proposalImageRepository.AddProposalImages(proposal.Id, viewModel.Images, _environment);
                    } catch { }

                    await _hub.Clients.Client(connectionId).SendAsync("Success", Messages.successCreateMessage);

                    // Добавление дополнительной записи
                    if (more)
                    {
                        return(RedirectToAction("Create", new {
                            ajaxLoad = true,
                            location = viewModel.Location
                        }));
                    } // if

                    return(RedirectToAction("Details", new { id = proposal.Id, ajaxLoad = true }));
                } //if
            }
            catch (DbUpdateException ex) { _message = DbErrorsInterpreter.GetDbUpdateExceptionMessage(ex); }
            catch { _message = Messages.createErrorMessage; } // try-catch

            if (_message != null)
            {
                if (_message != null)
                {
                    await _hub.Clients.Client(connectionId).SendAsync("Error", _message);
                }
            }
            return(PartialView(viewModel));
        } // Create