public ActionResult Create(Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(message));
        }
Esempio n. 2
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(PartialView("GridData", new Department[] { department }));
            }

            return(PartialView("Edit", department));
        }
        public ActionResult Create(PayType paytype)
        {
            if (ModelState.IsValid)
            {
                db.PayTypes.Add(paytype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(paytype));
        }
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(PartialView("GridData", new Company[] { company }));
            }

            return(PartialView("Edit", company));
        }
        public ActionResult Create(Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(PartialView("GridData", new Employee[] { employee }));
            }

            return(PartialView("Edit", employee));
        }
        public ActionResult Create(Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return(PartialView("GridData", new Message[] { message }));
            }

            return(PartialView("Edit", message));
        }
        public ActionResult Create(Holiday holiday)
        {
            if (ModelState.IsValid)
            {
                db.Holidays.Add(holiday);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(holiday));
        }
Esempio n. 8
0
        public ActionResult Create(Punch punch)
        {
            if (ModelState.IsValid)
            {
                db.Punches.Add(punch);
                db.SaveChanges();
                return(PartialView("GridData", new Punch[] { punch }));
            }

            ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", punch.EmployeeID);
            return(PartialView("Edit", punch));
        }
Esempio n. 9
0
        private static bool addLinesHelper(TimeClockContext db, Punch punch, Timecard tc, PayType pt, double weeklyWorked, double dailyWorked, DateTime splitStart, DateTime splitEnd, bool seventhDay)
        {
            // a simple base case, to stop spawing extra lines -- Not sure if this is needed
            if (splitStart.Subtract(splitEnd).TotalMinutes == 0)
            {
                return(true);
            }

            // Determin the correct pay type for this line.
            while (weeklyWorked > pt.getWeeklyMax(seventhDay))
            {
                pt = pt.NextPayType;
            }

            while (dailyWorked > pt.getDailyMax(seventhDay))
            {
                pt = pt.NextPayType;
            }

            // Calculate dailyLeft and weeklyLeft
            double dailyLeft  = (double)pt.getDailyMax(seventhDay) - dailyWorked;
            double weeklyLeft = (double)pt.getWeeklyMax(seventhDay) - dailyWorked;

            double splitLength = splitEnd.Subtract(splitStart).TotalMinutes;


            // Check if we reach over the weekly -- if
            if (weeklyWorked + splitLength > pt.getWeeklyMax(seventhDay))
            {
                addLinesHelper(db, punch, tc, pt, weeklyWorked, dailyWorked, splitStart, splitStart.AddMinutes(weeklyLeft), seventhDay);
                addLinesHelper(db, punch, tc, pt.NextPayType, weeklyWorked + weeklyLeft, dailyWorked + weeklyLeft, splitStart.AddMinutes(weeklyLeft), splitEnd, seventhDay);
            }
            // Check if we reached over the daily limit
            else if (dailyWorked + splitLength > pt.getDailyMax(seventhDay))
            {
                addLinesHelper(db, punch, tc, pt, weeklyWorked, dailyWorked, splitStart, splitStart.AddMinutes(dailyLeft), seventhDay);
                addLinesHelper(db, punch, tc, pt.NextPayType, weeklyWorked + dailyLeft, dailyWorked + dailyLeft, splitStart.AddMinutes(dailyLeft), splitEnd, seventhDay);
            }
            // we can safely add the line to the DB
            else
            {
                db.Lines.Add(new Line()
                {
                    TimecardID = tc.TimecardID,
                    PunchID    = punch.PunchID,
                    SplitStart = splitStart,
                    SplitEnd   = splitEnd,
                    PayTypeID  = pt.PayTypeID
                });
                db.SaveChanges();
            }

            return(true);
        }
Esempio n. 10
0
        public HttpResponseMessage <PunchResponse> Punch(PunchRequest request)
        {
            Employee emp = db.Employees.FirstOrDefault(e => e.EmployeeID.Equals(request.ID));

            if (!emp.Pin.Equals(request.pin)) // the pin didn't match don't do anything
            {
                PunchResponse response = new PunchResponse()
                {
                    isSuccess    = false,
                    pinError     = "Pin and user did not match.",
                    lines        = null,
                    generalError = null
                };

                return(new HttpResponseMessage <PunchResponse>(response));
            }
            else
            {
                var payPeriod   = PayPeriodTools.LookupPayPeriod(db, emp.DepartmentID);
                var curTimeCard = emp.Timecards.SingleOrDefault(tc => tc.PayPeriod == payPeriod.Start);

                PunchResponse retVal = new PunchResponse()
                {
                    isSuccess    = true,
                    pinError     = "",
                    generalError = null
                };

                if (request.closesPunch == -1)  // Create a new punch in the DB
                {
                    Punch temp = new Punch()
                    {
                        EmployeeID   = emp.EmployeeID,
                        InTime       = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0),
                        OutTime      = null,
                        DepartmentID = emp.DepartmentID,
                        PunchTypeID  = Constants.DEFAULT_PUNCH_TYPE // Make this equal to the Regular punch type.
                    };

                    db.Punches.Add(temp);
                    db.SaveChanges();

                    var timeCardData = TimeCardView.LinesToTimeCardView(db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart));
                    // We add the last line to just display the information, letting the user know that we register the punch in
                    timeCardData.Add(new TimeCardView()
                    {
                        DateText       = DateTime.Now.ToString(@"MM\/dd\/yy"),
                        InText         = temp.InTime.ToString(@"hh\:mm"),
                        OutText        = "",
                        RegularText    = "",
                        OvertimeText   = "",
                        DoubletimeText = ""
                    });

                    retVal.lines = timeCardData;
                }
                else // We need to close the last punch and make lines -- Make it split the lines over the payperiod seed
                {
                    // Set the ending time of the punch
                    Punch currentPunch = db.Punches.First(p => p.PunchID == request.closesPunch);
                    currentPunch.OutTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

                    var timeCardData = db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart).ToList();

                    retVal.lines = TimeCardView.LinesToTimeCardView(timeCardData);

                    if (currentPunch.OutTime.Value.Subtract(currentPunch.InTime).TotalMinutes < 1) // punch was shorter than a minut.
                    {
                        db.Punches.Remove(currentPunch);
                        retVal.lines.Add(new TimeCardView() // Make the last line show, but mark is as rapid since it won't get put in the DB
                        {
                            DateText       = currentPunch.InTime.ToString(@"MM\/dd\/yy"),
                            InText         = currentPunch.InTime.ToString(@"hh\:mm"),
                            OutText        = currentPunch.OutTime.Value.ToString(@"hh\:mm"),
                            RegularText    = "00:00",
                            OvertimeText   = "00:00",
                            DoubletimeText = "00:00",
                            isRapid        = true
                        });
                    }
                    else // Punch was longer than a minut, we add it to the DB.
                    {
                        Calculations.addLines(db, currentPunch);
                    }

                    db.SaveChanges();
                }

                return(new HttpResponseMessage <PunchResponse>(retVal));
            }
        }
Esempio n. 11
0
        public HttpResponseMessage <PunchResponse> Punch(PunchRequest request)
        {
            using (var db = new TimeClockContext())
            {
                /******************************************************************************    TODO ITEM    *********************************/
                //This is where we need to insert the new punch for the employee
                //If it is an out punch, we should recalculate their timecard lines.
                Employee emp = db.Employees.FirstOrDefault(e => e.EmployeeID.Equals(request.ID));

                if (!emp.Pin.Equals(request.pin))
                {
                    PunchResponse response = new PunchResponse()
                    {
                        isSuccess    = false,
                        pinError     = "Pin and user did not match.",
                        lines        = null,
                        generalError = null
                    };

                    return(new HttpResponseMessage <PunchResponse>(response));
                }
                else
                {
                    var payPeriod   = PayPeriodTools.LookupPayPeriod(db, emp.DepartmentID);
                    var curTimeCard = emp.Timecards.SingleOrDefault(tc => tc.PayPeriod == payPeriod.Start);

                    PunchResponse retVal = new PunchResponse()
                    {
                        isSuccess    = true,
                        pinError     = "",
                        generalError = null
                    };


                    if (request.closesPunch == -1)  // Create a new punch in the DB
                    {
                        Punch temp = new Punch()
                        {
                            EmployeeID   = emp.EmployeeID,
                            InTime       = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0),
                            OutTime      = null,
                            DepartmentID = emp.DepartmentID,
                            PunchTypeID  = Constants.DEFAULT_PUNCH_TYPE // Make this equal to the Regular punch type.
                                                                        //OutTime = null;
                        };

                        db.Punches.Add(temp);
                        db.SaveChanges();

                        var timeCardData = new List <TimeCardView>();
                        timeCardData.Add(new TimeCardView()
                        {
                            DateText       = DateTime.Now.ToString(@"MM\/dd\/yy"),
                            InText         = temp.InTime.ToString(@"hh\:mm"),
                            OutText        = "",
                            RegularText    = "",
                            OvertimeText   = "",
                            DoubletimeText = ""
                        });

                        retVal.lines = timeCardData;
                    }
                    else // We need to close the last punch and make lines -- Make it split the lines over the payperiod seed
                    {
                        // Set the ending time of the punch
                        Punch currentPunch = db.Punches.First(p => p.PunchID == request.closesPunch);
                        currentPunch.OutTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

                        if (currentPunch.OutTime.Value.Subtract(currentPunch.InTime).TotalMinutes < 1)
                        {
                            db.Punches.Remove(currentPunch);
                        }

                        db.SaveChanges();


                        Calculations.addLines(db, currentPunch);

                        var timeCardData = db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart).ToList();

                        retVal.lines = TimeCardView.LinesToTimeCardView(timeCardData);
                    }

                    /*
                     * PunchResponse retVal = new PunchResponse()
                     * {
                     *  isSuccess = true,
                     *  pinError = "",
                     *  lines = TimeCardView.LinesToTimeCardView(timeCardData),
                     *  generalError = null
                     * };
                     */
                    return(new HttpResponseMessage <PunchResponse>(retVal));
                }
            }
        }
Esempio n. 12
0
       private static bool addLinesHelper(TimeClockContext db, Punch punch, Timecard tc, PayType pt, double weeklyWorked, double dailyWorked, DateTime splitStart, DateTime splitEnd, bool seventhDay)
        {
            // a simple base case, to stop spawing extra lines -- Not sure if this is needed
            if (splitStart.Subtract(splitEnd).TotalMinutes == 0)
                return true;

        // Determin the correct pay type for this line.
           while (weeklyWorked > pt.getWeeklyMax(seventhDay))
               pt = pt.NextPayType;

           while (dailyWorked > pt.getDailyMax(seventhDay))
               pt = pt.NextPayType;

        // Calculate dailyLeft and weeklyLeft
           double dailyLeft = (double) pt.getDailyMax(seventhDay) - dailyWorked;
           double weeklyLeft = (double) pt.getWeeklyMax(seventhDay) - dailyWorked;

           double splitLength = splitEnd.Subtract(splitStart).TotalMinutes;


        // Check if we reach over the weekly -- if
           if (weeklyWorked + splitLength > pt.getWeeklyMax(seventhDay))
           {
               addLinesHelper(db, punch, tc, pt, weeklyWorked, dailyWorked, splitStart, splitStart.AddMinutes(weeklyLeft), seventhDay);
               addLinesHelper(db, punch, tc, pt.NextPayType, weeklyWorked + weeklyLeft, dailyWorked + weeklyLeft, splitStart.AddMinutes(weeklyLeft), splitEnd, seventhDay);
           }
               // Check if we reached over the daily limit
           else if (dailyWorked + splitLength > pt.getDailyMax(seventhDay))
           {
               addLinesHelper(db, punch, tc, pt, weeklyWorked, dailyWorked, splitStart, splitStart.AddMinutes(dailyLeft), seventhDay);
               addLinesHelper(db, punch, tc, pt.NextPayType, weeklyWorked + dailyLeft, dailyWorked + dailyLeft, splitStart.AddMinutes(dailyLeft), splitEnd, seventhDay);
           }
               // we can safely add the line to the DB
           else 
           { 
               db.Lines.Add(new Line()
                    {
                        TimecardID = tc.TimecardID,
                        PunchID = punch.PunchID,
                        SplitStart = splitStart,
                        SplitEnd = splitEnd,
                        PayTypeID = pt.PayTypeID
                    });
               db.SaveChanges();
             
           }

           return true;
       }