Esempio n. 1
0
        public FinancialEvent GenerateEvent()
        {
            FinancialEvent factory = new FinancialEvent();

            factory.EventName = this.EventName;
            factory.Balance   = 0;
            return(factory);
        }
        public static IActionResult GetEvent([HttpTrigger(AuthorizationLevel.Function, "get", Route = "event/{id}")] HttpRequest req,
                                             [CosmosDB(
                                                  databaseName: "Rodrap50",
                                                  collectionName: "Financials",
                                                  ConnectionStringSetting = "CosmosDBConnection",
                                                  Id = "{id}",
                                                  PartitionKey = "event")] FinancialEvent eventRecord,
                                             ILogger log)
        {
            log.LogInformation("C# HTTP GetEvent trigger function processed a request.");

            return(new OkObjectResult(eventRecord));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Title,Description,StartDate,EndDate,EventCategoryId,GoalId,GoalTypeId,EventStatusId")] Event newEvent, int financialAmount, int fitnessDistance, int fitnessDuration)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new ArgumentNullException("User.FindFirstValue(ClaimTypes.NameIdentifier)");

            newEvent.CreatedAt = DateTime.Now;
            newEvent.UserId    = User.FindFirstValue(ClaimTypes.NameIdentifier);


            if (ModelState.IsValid)
            {
                bool goalAdded = false;
                var  goalType  = await _context.GoalTypes.FindAsync(newEvent.GoalTypeId);

                var goalStatuses = await _context.GoalStatuses.ToListAsync();


                if (newEvent.GoalId != 0)
                {
                    goalAdded = true;
                }

                if (goalType.Name == "Financial")
                {
                    var financialEvent = new FinancialEvent {
                        Amount = financialAmount
                    };
                    var wallet = await _context.Wallets.Where(x => x.UserId == userId).ToListAsync();

                    wallet[0].Amount -= financialAmount;
                    _context.Update(wallet[0]);

                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.NumericalProgress += financialAmount;
                        if (goal.NumericalProgress >= goal.NumericalTarget)
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;
                        }
                        else
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "In Progress").Id;
                        }

                        _context.Update(goal);
                    }

                    await _context.FinancialEvents.AddAsync(financialEvent);

                    await _context.SaveChangesAsync();

                    newEvent.FinancialEventId = financialEvent.Id;
                }
                else if (goalType.Name == "Fitness")
                {
                    var fitnessEvent = new FitnessEvent();
                    fitnessEvent.Distance = fitnessDistance;
                    fitnessEvent.Duration = 0;

                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.NumericalProgress += fitnessDistance;
                        if (goal.NumericalProgress >= goal.NumericalTarget)
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;
                        }
                        else
                        {
                            goal.GoalStatusId = goalStatuses.Find(x => x.Status == "In Progress").Id;
                        }

                        _context.Update(goal);
                    }

                    await _context.FitnessEvents.AddAsync(fitnessEvent);

                    await _context.SaveChangesAsync();

                    newEvent.FitnessEventId = fitnessEvent.Id;
                }
                else if (goalType.Name == "General")
                {
                    if (goalAdded)
                    {
                        var goal = await _context.Goals.FindAsync(newEvent.GoalId);

                        goal.GoalStatusId = goalStatuses.Find(x => x.Status == "Succeeded").Id;

                        _context.Update(goal);
                    }
                    await _context.SaveChangesAsync();
                }

                await _context.AddAsync(newEvent);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(newEvent));
        }
 public void Consume(FinancialEvent @event)
 {
     _translator.Retranslate(@event);
 }