コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            ShiftLog shiftLog = db.ShiftLogs.Find(id);

            db.ShiftLogs.Remove(shiftLog);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public List<ShiftLog> LogWorkingHours(string employeeID)
        {
            connection.Open();
            
            var getTotalRecords = connection.CreateCommand();
            getTotalRecords.CommandText = "select guid guid, dtcreated DTCreated, type, comment  from Log where resource='" + employeeID + "' and type in (0,1) order by dtcreated ASC ;";
            getTotalRecords.CommandType = CommandType.Text;
            SqliteDataReader sqlite_datareader = getTotalRecords.ExecuteReader();
            
            List<Log> logList = sqlite_datareader.Cast<IDataRecord>()
                    .Select(dr => new Log
                    {
                        OID = dr["guid"].ToString(),
                        Type = (LogType)int.Parse(dr["Type"].ToString()),
                        //Resource = (Employee)dr["Resource"],
                        Comment = (string)dr["Comment"],
                        DTCreated = new DateTime(long.Parse(dr["DTCreated"].ToString()))
                    }).ToList();

            connection.Close();

            IShiftService _shiftService = new ShiftService();
            List<Shift> shiftList = _shiftService.GetShifts();

            List<ShiftLog> shiftLogList = new List<ShiftLog>();
            for (int a=0; a< logList.Count;a++)
            {
                ShiftLog sh = new ShiftLog();
                sh.TimeFrom = logList[a].DTCreated;
                // Fetch rate for this shift from comments
                if (!string.IsNullOrEmpty(logList[a].Comment))
                    sh.Rate = double.Parse(logList[a].Comment);

                if (a!= logList.Count-1 &&  logList[a + 1].Type == LogType.Logout)
                {
                    // in case worker logs in and out we skip second iteration.
                    sh.TimeTill = logList[a + 1].DTCreated;
                    TimeSpan durationTmsp = sh.TimeTill.TimeOfDay - sh.TimeFrom.TimeOfDay;
                    sh.Hours = Math.Round(durationTmsp.TotalHours,2);
                    sh.DisplayHours = string.Format("{0}:{1}", durationTmsp.Hours, durationTmsp.Minutes);
                    a++;
                }
                else
                {
                    // If worker didnt log out set default date span
                    Shift ss = shiftList.FirstOrDefault(shft => shft.Category == EventCategory.WorkingTime);
                    TimeSpan durationTmsp = ss.EndTime - sh.TimeFrom.TimeOfDay;
                    sh.Hours = Math.Round(durationTmsp.TotalHours,2);
                    sh.DisplayHours = string.Format("{0}:{1}", durationTmsp.Hours, durationTmsp.Minutes);
                    sh.TimeTill = sh.TimeFrom.AddMinutes(durationTmsp.TotalMinutes);// Temporary; TODO: add shift dictionary to get default working hours
                }
                shiftLogList.Add(sh);
            }
            return shiftLogList;
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "ShiftLogId,ShiftTaskGroupId,Shift,Date,Text,PictureId")] ShiftLog shiftLog)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shiftLog).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ShiftTaskGroupId = new SelectList(db.ShiftTaskGroups, "ShiftTaskGroupId", "ShiftTaskGroupName", shiftLog.ShiftTaskGroupId);
     return(View(shiftLog));
 }
コード例 #4
0
        // GET: ShiftLog/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShiftLog shiftLog = db.ShiftLogs.Find(id);

            if (shiftLog == null)
            {
                return(HttpNotFound());
            }
            return(View(shiftLog));
        }
コード例 #5
0
        // GET: ShiftLog/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShiftLog shiftLog = db.ShiftLogs.Find(id);

            if (shiftLog == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ShiftTaskGroupId = new SelectList(db.ShiftTaskGroups, "ShiftTaskGroupId", "ShiftTaskGroupName", shiftLog.ShiftTaskGroupId);
            return(View(shiftLog));
        }