示例#1
0
        public ActionResult CreateNew([FromBody] WorkAssignments workAssignment)
        {
            tuntidbContext db = new tuntidbContext();

            try
            {
                db.WorkAssignments.Add(workAssignment);
                db.SaveChanges();
                return(Ok(workAssignment.IdWorkAssignment));
            }
            catch
            {
                return(BadRequest("Adding work assignment failed"));
            }
            finally
            {
                db.Dispose();
            }
        }
        public ActionResult CreateNew([FromBody] Employees emp)
        {
            tuntidbContext db = new tuntidbContext();

            try
            {
                db.Employees.Add(emp);
                db.SaveChanges();
                return(Ok(emp.IdEmployee));
            }
            catch
            {
                return(BadRequest("Adding employee failed"));
            }
            finally
            {
                db.Dispose();
            }
        }
        public bool StartStop(Operation op)
        {
            if (op == null)
            {
                return(false);
            }

            WorkAssignment assignment = (from w in db.WorkAssignments
                                         where (w.Active == true) &&
                                         (w.IdWorkAssingment == op.WorkAssidnmentID)
                                         select w).FirstOrDefault();

            if (assignment == null)
            {
                return(false);
            }


            // -----------------------------Start------------------------------------------------------------------
            else if (op.OperationType == "start")
            {
                if (assignment.InProgress == true || assignment.Completed == true)
                {
                    return(false);
                }

                assignment.InProgress     = true;
                assignment.WorkStartedAt  = DateTime.Now.AddHours(3);
                assignment.LastModifiedAt = DateTime.Now.AddHours(3);
                db.SaveChanges();

                Timesheet newEntry = new Timesheet()
                {
                    IdWorkAssignment = op.WorkAssidnmentID,
                    StartTime        = DateTime.Now.AddHours(3),
                    Active           = true,
                    IdEmployee       = op.EmployeeID,
                    IdCustomer       = op.CustomerID,
                    CreatedAt        = DateTime.Now.AddHours(3),
                    Comments         = op.Comment,
                    Latitude         = op.Latitude,
                    Longitude        = op.Longitude
                };

                db.Timesheets.Add(newEntry);
                db.SaveChanges();
                return(true);
            }
            // -------------------- IF STOP ------------------------------------------------------------------------
            else
            {
                if (assignment.InProgress == false || assignment.Completed == true)
                {
                    return(false);
                }

                assignment.InProgress     = false;
                assignment.CompletedAt    = DateTime.Now.AddHours(3);
                assignment.Completed      = true;
                assignment.LastModifiedAt = DateTime.Now.AddHours(3);

                Timesheet ts = (from t in db.Timesheets
                                where (t.Active == true) &&
                                (t.IdWorkAssignment == op.WorkAssidnmentID)
                                select t).FirstOrDefault();

                ts.StopTime       = DateTime.Now.AddHours(3);
                ts.LastModifiedAt = DateTime.Now.AddHours(3);
                ts.Comments       = op.Comment;
                ts.Longitude      = op.Longitude;
                ts.Latitude       = op.Latitude;
                db.SaveChanges();

                return(true);
            }
        }
示例#4
0
        public bool PostStatus(WorkAssignmentOperationModel input) // Todo: Ota myös customer ja employee tieto
        {
            tuntidbContext context = new tuntidbContext();

            try
            {       //Ensin haetaan työtehtävä Otsikon (title) perusteella ja nimetään se assignment muuttujaksi
                WorkAssignments assignment = (from wa in context.WorkAssignments
                                              where (wa.Active == true) &&
                                              (wa.Title == input.AssignmentTitle)
                                              select wa).FirstOrDefault();

                if (assignment == null)
                {
                    return(false);
                }

                //--------------------------IF--START----------------------------------------------------------------------

                else if (input.Operation == "Start")
                {
                    if (assignment.InProgress == true || assignment.Completed == true) // Lisätty 4.5.

                    {
                        return(false);
                    }
                    else
                    {
                        int assignmentId = assignment.IdWorkAssignment;

                        // Luodaan uusi timesheet työlle

                        Timesheet newEntry = new Timesheet()
                        {
                            IdWorkAssignment = assignmentId,
                            StartTime        = DateTime.Now,
                            //WorkComplete = false, ------------ poistettu turha kenttä
                            Active    = true,
                            CreatedAt = DateTime.Now
                        };

                        context.Timesheet.Add(newEntry);

                        // Päivitetään työtehtävän tilaa myös work assignments tauluun

                        WorkAssignments assignments = (from wa in context.WorkAssignments
                                                       where (wa.IdWorkAssignment == assignmentId) &&
                                                       (wa.Active == true)
                                                       select wa).FirstOrDefault();

                        assignment.InProgress     = true;
                        assignment.WorkStartedAt  = DateTime.Now;
                        assignment.LastModifiedAt = DateTime.Now;

                        context.SaveChanges(); // talletetaan kaikki em muutokset
                    }
                }

                //--------------------------------IF--STOP----------------------------------------------------------------------

                else if (input.Operation == "Stop")
                {
                    int assignmentId = assignment.IdWorkAssignment;

                    // Halutaan muuttaa tietoja sekä timesheetiin...

                    Timesheet existing = (from ts in context.Timesheet
                                          where (ts.IdWorkAssignment == assignmentId) &&
                                          (ts.Active == true)
                                          select ts).FirstOrDefault();

                    //............että work assignmentteihin

                    WorkAssignments assignments = (from wa in context.WorkAssignments
                                                   where (wa.IdWorkAssignment == assignmentId) &&
                                                   (wa.Active == true)
                                                   select wa).FirstOrDefault();

                    if (existing != null && assignment != null)
                    {
                        if (assignment.InProgress == false || assignment.Completed == true) // Muutettu 4.5.

                        {
                            return(false);
                        }
                        else
                        {
                            // Timesheetin uudet arvot

                            existing.StopTime       = DateTime.Now;
                            existing.WorkComplete   = true;
                            existing.LastModifiedAt = DateTime.Now;


                            // Assignmentin uudet arvot

                            assignment.LastModifiedAt = DateTime.Now;
                            assignment.Completed      = true;
                            assignment.CompletedAt    = DateTime.Now;
                            assignment.InProgress     = false;
                        }
                    }

                    else
                    {
                        return(false); // Jos id tieto on null jommassa kummassa.
                    }
                }

                context.SaveChanges();     // talletetaan kaikki em muutokset
            }

            catch
            {
                return(false); // Jos jotain muuta menee pileen.
            }

            finally
            {
                context.Dispose();
            }
            return(true); // Mobiilisovellukselle palautetaan true
        }
示例#5
0
        public bool StartStop(Operation op)
        {
            if (op == null)
            {
                return(false);
            }

            WorkAssignment assignment = (from w in db.WorkAssignments
                                         where (w.Active == true) &&
                                         (w.IdWorkAssignment == op.WorkAssignmentID)
                                         select w).FirstOrDefault();

            if (assignment == null)
            {
                return(false);
            }

            // Start
            else if (op.OperationType == "start")
            {
                if (assignment.InProgress == true || assignment.Completed == true)
                {
                    return(false);
                }

                assignment.InProgress     = true;
                assignment.WorkStartedAt  = DateTime.Now.AddHours(2);
                assignment.LastModifiedAt = DateTime.Now.AddHours(2);

                db.SaveChanges();


                Timesheet newEntry = new Timesheet()
                {
                    IdWorkAssignment = op.WorkAssignmentID,
                    StartTime        = DateTime.Now.AddHours(2),
                    Active           = true,
                    IdEmployee       = op.EmployeeID,
                    IdCustomer       = op.CustomerID,
                    CreatedAt        = DateTime.Now.AddHours(2),
                    Comments         = op.Comment
                };

                db.Timesheets.Add(newEntry);

                db.SaveChanges(); //<-------------- Tämä puuttui, ja siksi ei luonutkaan uutta timesheetiä. Ongelma ilmeni salakavalasti vasta STOP vaiheessa

                return(true);
            }

            // Stop
            else
            {
                if (assignment.InProgress == false || assignment.Completed == true)
                {
                    return(false);
                }

                assignment.InProgress     = false;
                assignment.CompletedAt    = DateTime.Now.AddHours(2);
                assignment.Completed      = true;
                assignment.LastModifiedAt = DateTime.Now.AddHours(2);
                db.SaveChanges();

                Timesheet ts = (from t in db.Timesheets
                                where (t.Active == true) &&
                                (t.IdWorkAssignment == op.WorkAssignmentID)
                                select t).FirstOrDefault();

                ts.StopTime       = DateTime.Now.AddHours(2);
                ts.LastModifiedAt = DateTime.Now.AddHours(2);
                ts.Comments       = op.Comment;
                db.SaveChanges();

                return(true);
            }
        }