示例#1
0
        public async Task <int> AddActualIntencive(ActualIntencive actual)
        {
            if (_db != null)
            {
                await _db.ActualIntencive.AddAsync(actual);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
示例#2
0
        public async Task <int> UpdateActualIntencive(int id, ActualIntencive actual)
        {
            if (_db != null)
            {
                ActualIntencive existItem = _db.ActualIntencive
                                            .Where(f => f.IdactualIntencive == id).FirstOrDefault();
                if (existItem != null)
                {
                    existItem.ActualIntencive1 = actual.ActualIntencive1;
                    existItem.Date             = actual.Date;
                    existItem.IdUser           = actual.IdUser;
                }

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

                return(1);
            }
            return(0);
        }
示例#3
0
        public async Task <IActionResult> UpdateActualIntencive(ActualIntencive actual, int id)
        {
            try
            {
                var result = await _intencive.UpdateActualIntencive(id, actual);

                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());
            }
        }
示例#4
0
        public async Task <List <(string, double)> > GetActualIntenciveByUser(string user, string period, DateTime start, DateTime end)
        {
            try
            {
                if (period == "monthly")
                {
                    //Define list of Actual intencives to store the result
                    List <(string, double)> result = new List <(string, double)>();
                    for (var month = start.Month; month <= end.Month; month++)
                    {
                        //to store the all actual intencives
                        Double value = 0;

                        //return list of id actual intencives in each month
                        List <int> actualintencives = await _db.ActualIntencive
                                                      .Where(x => x.Date.Value.Month == month && x.IdUser == user)
                                                      .Select(x => x.IdactualIntencive).ToListAsync();

                        var userName = _db.Aspnetusers.Where(x => x.Id == user).Select(x => x.FullName).SingleOrDefault();
                        for (int j = 0; j < actualintencives.Count; j++)
                        {
                            ActualIntencive subResult = await GetDailyActualIntencive(actualintencives[j]);

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


                    return(result);
                }
                else if (period == "annual")
                {
                    //Define list of Actual intencives 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 Actual intencives
                        Double value = 0;

                        //return list of id_Actual intencives in each day
                        List <int> actualintencives = await _db.ActualIntencive
                                                      .Where(x => x.Date.Value.Year == year && x.IdUser == user)
                                                      .Select(x => x.IdactualIntencive).ToListAsync();

                        for (int j = 0; j < actualintencives.Count; j++)
                        {
                            ActualIntencive subResult = await GetDailyActualIntencive(actualintencives[j]);

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


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


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