Ejemplo n.º 1
0
        public async Task <int> AddExpectedIntencive(ExpectedIntencive expected)
        {
            if (_db != null)
            {
                await _db.ExpectedIntencive.AddAsync(expected);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public async Task <int> UpdateExpectedIntencive(int id, ExpectedIntencive expected)
        {
            if (_db != null)
            {
                ExpectedIntencive existItem = _db.ExpectedIntencive
                                              .Where(f => f.IdexpectedIntencive == id).FirstOrDefault();
                if (existItem != null)
                {
                    existItem.ExpectedMoney = expected.ExpectedMoney;
                    existItem.Date          = expected.Date;
                    existItem.UserId        = expected.UserId;
                }

                _db.ExpectedIntencive.Update(existItem);
                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateExpectedIntencive(ExpectedIntencive expected, int id)
        {
            try
            {
                var result = await _intencive.UpdateExpectedIntencive(id, expected);

                if (result != 0)
                {
                    var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result);
                    return(Ok(Response));
                }

                else
                {
                    var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                    return(Ok(Response));
                }
            }

            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 4
0
        public async Task <List <(string, double)> > GetExpectedIntenciveByUser(string user, string period, DateTime start, DateTime end)
        {
            try
            {
                if (period == "monthly")
                {
                    //Define list of Expected intencive to store the result
                    List <(string, double)> result = new List <(string, double)>();
                    var userName = _db.Aspnetusers.Where(x => x.Id == user).Select(x => x.FullName).SingleOrDefault();
                    for (var month = start.Month; month <= end.Month; month++)
                    {
                        //to store the all expected intencive
                        Double value = 0;

                        //return list of id expected intencive in each day
                        List <int> expectedintencive = await _db.ExpectedIntencive
                                                       .Where(x => x.Date.Value.Month == month && x.UserId == user)
                                                       .Select(x => x.IdexpectedIntencive).ToListAsync();

                        for (int j = 0; j < expectedintencive.Count; j++)
                        {
                            ExpectedIntencive subResult = await GetDailyExpectedIntencive(expectedintencive[j]);

                            value += Convert.ToDouble(subResult.ExpectedMoney);
                        }
                        result.Add((userName, value));
                    }


                    return(result);
                }
                else if (period == "annual")
                {
                    //Define list of expected intencive to store the result
                    List <(string, double)> result = new List <(string, double)>();
                    var userName = _db.Aspnetusers.Where(x => x.Id == user).Select(x => x.FullName).SingleOrDefault();
                    for (var year = start.Year; year <= end.Year; year++)
                    {
                        //to store the full expected intencive
                        Double value = 0;

                        //return list of id_expected intencive in each day
                        List <int> expectedintencive = await _db.ExpectedIntencive
                                                       .Where(x => x.Date.Value.Year == year && x.UserId == user)
                                                       .Select(x => x.IdexpectedIntencive).ToListAsync();

                        for (int j = 0; j < expectedintencive.Count; j++)
                        {
                            ExpectedIntencive subResult = await GetDailyExpectedIntencive(expectedintencive[j]);

                            value += Convert.ToDouble(subResult.ExpectedMoney);
                        }
                        result.Add((userName, value));
                    }


                    return(result);
                }
                return(null);
            }


            catch (Exception)
            {
                return(null);
            }
        }