Esempio n. 1
0
 public async Task ClearDb()
 {
     _uow.DiseaseSymptoms.Clear();
     _uow.Diseases.Clear();
     _uow.Symptoms.Clear();
     await _uow.SaveChangesAsync();
 }
Esempio n. 2
0
        public async Task <DiseaseDTO> AddAsync(DiseaseDTO dto)
        {
            var disease = DiseaseDTO.CreateFromDTO(dto);
            await _uow.Diseases.AddAsync(disease);

            if (dto.Symptoms.Any())
            {
                foreach (var dtoSymptom in dto.Symptoms)
                {
                    var symptom = await _uow.Symptoms.FindAsync(dtoSymptom.SymptomId);

                    if (symptom == null)
                    {
                        symptom = new Symptom()
                        {
                            SymptomName = dtoSymptom.SymptomName
                        };
                        await _uow.Symptoms.AddAsync(symptom);
                    }
                    await _uow.DiseaseSymptoms.AddAsync(new DiseaseSymptom()
                    {
                        Disease = disease, Symptom = symptom
                    });
                }
            }

            await _uow.SaveChangesAsync();

            return(DiseaseDTO.CreateFromDomain(disease));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ReceiptParticipantId,IsPaid,LoanGiverId,LoanTakerId,Id")]
                                                 Loan loan)
        {
            if (ModelState.IsValid)
            {
                await _uow.Loans.AddAsync(loan);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var viewModel = new LoanViewModel
            {
                Loan       = loan,
                LoanGivers = new SelectList(await _uow.BaseRepository <AppUser>().AllAsync(), nameof(AppUser.Id),
                                            nameof(AppUser.UserNickname), loan.LoanGiverId),
                LoanTakers = new SelectList(await _uow.BaseRepository <AppUser>().AllAsync(), nameof(AppUser.Id),
                                            nameof(AppUser.UserNickname), loan.LoanTakerId),
                ReceiptParticipants = new SelectList(await _uow.ReceiptParticipants.AllAsync(),
                                                     nameof(ReceiptParticipant.Id), nameof(ReceiptParticipant.Id), loan.ReceiptParticipantId)
            };

            return(View(viewModel));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Value,ProductId,ChangeId,ValidFrom,ValidTo")]
                                                 Price price)
        {
            if (ModelState.IsValid)
            {
                await _uow.Prices.AddAsync(price);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var changes = new SelectList(await _uow.Changes.AllAsync(), "Id", "ChangeName", price.ChangeId)
                          .Prepend(new SelectListItem {
                Text = "Select change", Value = ""
            });
            var products = new SelectList(await _uow.Products.AllAsync(), "Id", "ProductName", price.ProductId)
                           .Prepend(new SelectListItem {
                Text = "Select product", Value = ""
            });

            var viewModel = new PriceViewModel
            {
                Price = price, ChangeSelectList = changes, ProductSelectList = products
            };

            return(View(viewModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Bidding(Bidding currentBidding)
        {
            currentBidding.BiddingTime = DateTime.Now;
            var existingBid = await _uow.Biddings.FindAsync(currentBidding.AuctionId);

            if (existingBid == null)
            {
                if (ModelState.IsValid)
                {
                    await _uow.Biddings.AddAsync(currentBidding);

                    await _uow.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                if (existingBid.Bid < currentBidding.Bid)
                {
                    _uow.Biddings.Update(currentBidding);
                    await _uow.SaveChangesAsync();
                }
            }
            return(View());
        }
        public async Task <ActionResult <Currency> > PostCurrency(Currency currency)
        {
            await _uow.Currencies.AddAsync(currency);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Currency added: {ID}", currency.Id);
            return(CreatedAtAction("GetCurrency", new { id = currency.Id }, currency));
        }
        public async Task <ActionResult <PaymentMethod> > PostPaymentMethod(PaymentMethod paymentMethod)
        {
            await _uow.PaymentMethods.AddAsync(paymentMethod);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Payment method created: {ID}", paymentMethod.Id);
            return(CreatedAtAction("GetPaymentMethod", new { id = paymentMethod.Id }, paymentMethod));
        }
Esempio n. 8
0
        public async Task <ActionResult <Product> > PostProduct(Product product)
        {
            await _uow.Products.AddAsync(product);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Product created: {ID},", product.Id);
            return(CreatedAtAction("GetProduct", new { id = product.Id }, product));
        }
Esempio n. 9
0
        public async Task <ActionResult <Account> > PostAccount(Account account)
        {
            await _uow.Accounts.AddAsync(account);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Account created: {ID}, user-id: {USER}", account.Id, account.UserId);
            return(CreatedAtAction("GetAccount", new { id = account.Id }, account));
        }
        public async Task <ActionResult <Payment> > PostPayment(Payment payment)
        {
            await _uow.Payments.AddAsync(payment);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Payment created: {ID}, user-id: {USER}", payment.Id, payment.UserId);
            return(CreatedAtAction("GetPayment", new { id = payment.Id }, payment));
        }
Esempio n. 11
0
        public async Task <SymptomDTO> AddAsync(SymptomDTO dto)
        {
            var symptom = SymptomDTO.CreateFromDTO(dto);

            await _uow.Symptoms.AddAsync(symptom);

            await _uow.SaveChangesAsync();

            return(SymptomDTO.CreateFromDomain(symptom));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("ComponentTypeName,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] ComponentType componentType)
        {
            if (ModelState.IsValid)
            {
                _uow.ComponentTypes.Add(componentType);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentType));
        }
        public async Task <IActionResult> Create(CompanyTypeCreateEditVM vm)
        {
            if (ModelState.IsValid)
            {
                vm.CompanyType.CompanyTypeName = new MultiLangString(vm.CompanyTypeName);
                _uow.CompanyTypes.Add(vm.CompanyType);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("PersonId,FirstName,LastName")] Person person)
        {
            if (ModelState.IsValid)
            {
                await _uow.People.AddAsync(person);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
        public async Task <IActionResult> Create(AnswersCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.Answer.Id = Guid.NewGuid();
                _uow.Answers.Add(vm.Answer);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create(ProjectsCreateEditVM vm)
        {
            if (ModelState.IsValid)
            {
                _uow.Projects.Add(vm.Project);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            vm.ProjectTypeSelectList = new SelectList(_uow.ProjectTypes.All(), nameof(ProjectType.ProjectTypeId), nameof(ProjectType.ProjectTypeName), vm.Project.ProjectTypeId);
            return(View(vm));
        }
        public async Task <IActionResult> PutChoice(Guid id, Choice choice)
        {
            if (id != choice.Id)
            {
                return(BadRequest());
            }

            await _uow.Choices.UpdateAsync(_mapper.Map(choice));

            await _uow.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> PutAnswer(Guid id, Answer answer)
        {
            if (id != answer.Id)
            {
                return(BadRequest());
            }

            await _uow.Answers.UpdateAsync(_mapper.Map(answer));

            await _uow.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 19
0
        public async Task <IActionResult> Create([Bind("OrganizationName,Id")] Organization organization)
        {
            if (ModelState.IsValid)
            {
                await _uow.Organizations.AddAsync(organization);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(organization));
        }
Esempio n. 20
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.Id)
            {
                return(BadRequest());
            }

            _uow.Categories.Update(category);
            await _uow.SaveChangesAsync();

            _logger.LogInformation("Category updated: {ID}", category.Id);
            return(NoContent());
        }
Esempio n. 21
0
        public async Task <IActionResult> Create(QuizzesCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.Quiz.Id        = Guid.NewGuid();
                vm.Quiz.AppUserId = User.UserGuidId();
                _uow.Quizzes.Add(vm.Quiz);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = vm.Quiz.Id }));
            }

            return(View(vm));
        }
Esempio n. 22
0
        public async Task <IActionResult> Create(ChoicesCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.Choice.Id = Guid.NewGuid();
                _uow.Choices.Add(vm.Choice);
                await _uow.SaveChangesAsync();

                return(RedirectToAction("Details", "Questions", new { id = vm.Choice.QuestionId }));
            }

            vm.Questions = new SelectList(await _uow.Questions.GetAllAsync(), nameof(Question.Id),
                                          nameof(Question.Title));
            return(View(vm));
        }
Esempio n. 23
0
        public async Task <IActionResult> Create(QuizSessionsCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.QuizSession.Id = Guid.NewGuid();
                _uow.QuizSessions.Add(vm.QuizSession);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            vm.Users = new SelectList(await _userManager.Users.ToListAsync(), nameof(AppUser.Id),
                                      nameof(AppUser.FullName));
            vm.Quizzes = new SelectList(await _uow.Quizzes.GetAllAsync(), nameof(Quiz.Id), nameof(Quiz.Title));
            return(View(vm));
        }
        public async Task <IActionResult> PutQuizSession(Guid id, QuizSession quizSession)
        {
            if (id != quizSession.Id)
            {
                return(BadRequest());
            }

            var dalEntity = _mapper.Map(quizSession);

            dalEntity.AppUserId = User.UserGuidId();
            await _uow.QuizSessions.UpdateAsync(dalEntity);

            await _uow.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> PutQuestion(Guid id, Question question)
        {
            if (id != question.Id)
            {
                return(BadRequest());
            }

            if (!await _uow.Questions.ExistsAsync(question.Id))
            {
                return(NotFound());
            }

            await _uow.Questions.UpdateAsync(_mapper.Map(question));

            await _uow.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> PutPerson(int id, Person person)
        {
            if (person == null || id != person.Id)
            {
                return(BadRequest());
            }

            if (person.FirstName.Length < 1 || person.FirstName.Length > 128 ||
                person.LastName.Length < 1 || person.LastName.Length > 128 ||
                person.Age < 0 || person.Age > 122)
            {
                return(BadRequest());
            }

            _uow.Persons.Update(person);
            await _uow.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 27
0
        public async Task <ActionResult <Bet> > PostBet(Bet bet)
        {
            // TODO: get user id from jwt context
            await _uow.Bets.AddAsync(bet);

            await _uow.SaveChangesAsync();

            _logger.LogInformation("Bet placed: {ID}, user-id: {USER}", bet.Id, bet.UserId);
            return(CreatedAtAction("GetBet", new { id = bet.Id }, bet));
        }
        public async Task <IActionResult> PutPersonInRelationship(int id, PersonInRelationship personInRelationship)
        {
            if (id != personInRelationship.Id)
            {
                return(BadRequest());
            }

            if ((await ValidateRelationship(personInRelationship)) == false)
            {
                return(BadRequest());
            }

            await AddBackwardsRelationIfNeeded(personInRelationship);

            _uow.PersonInRelationships.Update(personInRelationship);
            await _uow.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 29
0
        public async Task <IActionResult> Create([Bind("ReceiptRowId,ChangeId,Id")] ReceiptRowChange receiptRowChange)
        {
            if (ModelState.IsValid)
            {
                Console.WriteLine(receiptRowChange);
                await _uow.ReceiptRowChanges.AddAsync(receiptRowChange);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var viewModel = new ReceiptRowChangeViewModel
            {
                ReceiptRowChange = receiptRowChange,
                Changes          = new SelectList(await _uow.Changes.AllAsync(), nameof(Change.Id), nameof(Change.ChangeName)),
                Rows             = new SelectList(await _uow.ReceiptRows.AllAsync(), nameof(ReceiptRow.Id), nameof(ReceiptRow.Id))
            };

            return(View(viewModel));
        }
Esempio n. 30
0
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                await _uow.Products.AddAsync(product);

                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var viewModel = new ProductViewModel
            {
                Product       = product,
                Organizations = new SelectList(await _uow.Organizations.AllAsync(), nameof(Organization.Id),
                                               nameof(Organization.OrganizationName))
            };

            return(View(viewModel));
        }