Example #1
0
        public async Task <IActionResult> TinhLaiNhatKy()
        {
            try
            {
                var or = _context.CV_QT_WorkNote.Where(x => x.DateEnd != null).ToList();
                foreach (var item in or)
                {
                    item.WorkTime = SpaceTimeOnDay.CalSpaceTimeOnDay(item.DateStart ?? DateTime.Now, item.DateEnd ?? DateTime.Now) / 60;
                }
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0 }));
            }
            catch (Exception)
            {
                return(NoContent());
            }
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <CV_QT_MyWork> > > r1SpaceTimeOnDay()
        {
            try
            {
                TimeSpan     ts17  = new TimeSpan(17, 00, 0);
                RequestToken token = CommonData.GetDataFromToken(User);

                var datesDefault = TransforDate.FromDateToDouble(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01));
                var dateeDefault = TransforDate.FromDateToDouble(DateTime.Now);
                var reports      = (from a in _context.CV_QT_StartPauseHistory
                                    where a.UserCreateId == token.UserID && a.Done != true && a.CreateDate.Month == DateTime.Now.Month
                                    orderby a.Id
                                    select new
                {
                    a.Id,
                    a.CreateDate,
                    a.CycleWork,
                    a.MyWorkId,
                    a.UserCreateId
                }).ToList();
                if (reports.Count() < 2)
                {
                    return(new ObjectResult(new { error = 0 }));
                }
                List <CV_QT_SpaceTimeOnDay> listSpace = new List <CV_QT_SpaceTimeOnDay>();

                for (int i = 0; i < reports.Count() - 1; i++)
                {
                    if (reports[i].CreateDate.Hour >= 17 && reports[i].CreateDate.Minute > 3)
                    {
                        continue;
                    }
                    if (reports[i].CycleWork == 2)
                    {
                        CV_QT_SpaceTimeOnDay obj = new CV_QT_SpaceTimeOnDay()
                        {
                            SpaceStart = TransforDate.FromDateToDouble(reports[i].CreateDate),
                            SpaceEnd   = TransforDate.FromDateToDouble(reports[i + 1].CreateDate),
                            Time       = SpaceTimeOnDay.CalSpaceTimeOnDay(reports[i].CreateDate, reports[i + 1].CreateDate),
                            MyWorkId   = reports[i].MyWorkId,
                            UserId     = reports[i].UserCreateId
                        };
                        if (obj.Time >= 30)
                        {
                            listSpace.Add(obj);
                        }
                    }
                }
                var objup = _context.CV_QT_StartPauseHistory.Where(x => x.UserCreateId == token.UserID && x.Done != true);
                foreach (var item in objup)
                {
                    item.Done = true;
                }
                _context.CV_QT_StartPauseHistory.UpdateRange(objup);
                await _context.AddRangeAsync(listSpace);

                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0 }));
            }
            catch (Exception e)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }