public ActionResult GetAllActiveWorkAssignments()
 {
     try
     {
         var wa = (from w in db.WorkAssignments where w.Active == true && w.Completed == false select w).ToList();
         return(Ok(wa));
     }
     catch (Exception e)
     {
         return(BadRequest("Virhe: " + e));
     }
     finally
     {
         db.Dispose();
     }
 }
 public ActionResult GetAllActiveEmployees()
 {
     try
     {
         var emp = (from e in db.Employees where e.Active == true select e).ToList();
         return(Ok(emp));
     }
     catch (Exception e)
     {
         return(BadRequest("Virhe: " + e));
     }
     finally
     {
         db.Dispose();
     }
 }
示例#3
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();
            }
        }
示例#5
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
        }