Exemple #1
0
        public ActionResult Delete(int id)
        {
            var db    = new TimeCardContext();
            var model = db.Employees.Find(id);

            return(View(model));
        }
 public IEnumerable <TimeCardDTO> GetTimeCardsByDate(DateTime startDate)
 {
     using (var context = new TimeCardContext())
     {
         return(context.TimeCards.Where(tc => tc.StartDate.Equals(startDate)).Select(tc => tc.ToDTO(true)));
     }
 }
Exemple #3
0
        public ActionResult Index()
        {
            var db    = new TimeCardContext();
            var model = db.Employees;

            return(View(model));
        }
Exemple #4
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            var db       = new TimeCardContext();
            var employee = db.Employees.Find(id);

            db.Employees.Remove(employee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void AddEmployee(EmployeeDTO employee)
        {
            using (var context = new TimeCardContext())
            {
                context.Employees.Add(employee.ToDomain(true));

                context.SaveChanges();
            }
        }
        public void AddTimeCard(TimeCardDTO timeCard)
        {
            using (var context = new TimeCardContext())
            {
                context.TimeCards.Add(timeCard.ToDomain(true));

                context.SaveChanges();
            }
        }
Exemple #7
0
 public void AddEntry(clsTimeEntry newEntry)
 {
     using (TimeCardContext context = new TimeCardContext())
     {
         newEntry.DateTimeLastMaint = DateTime.Now.Date;
         context.TimeCardEntries.Add(newEntry);
         context.SaveChanges();
     }
 }
        public TimeCardDTO GetTimeCard(int id)
        {
            using (var context = new TimeCardContext())
            {
                var timeCard = context.TimeCards.Find(id);

                return(timeCard != null?timeCard.ToDTO(true) : null);
            }
        }
        public IEnumerable <TimeCardDTO> GetTimeCardsForEmployee(int employeeId)
        {
            using (var context = new TimeCardContext())
            {
                var employee = context.Employees.Find(employeeId);

                return(employee != null?employee.TimeCards.Select(tc => tc.ToDTO(true)) : new List <TimeCardDTO>());
            }
        }
        public EmployeeDTO GetEmployee(int id, bool includeTimeCards)
        {
            using (var context = new TimeCardContext())
            {
                var employee = context.Employees.Find(id);

                return(employee != null?employee.ToDTO(includeTimeCards) : null);
            }
        }
Exemple #11
0
 public ActionResult Create(Employee newEmployee)
 {
     if (ModelState.IsValid)
     {
         var db = new TimeCardContext();
         db.Employees.Add(newEmployee);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(newEmployee));
 }
Exemple #12
0
 public ActionResult Edit(Employee updatedEmployee)
 {
     if (ModelState.IsValid)
     {
         var db = new TimeCardContext();
         db.Entry(updatedEmployee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(updatedEmployee));
 }
Exemple #13
0
 public void DeleteEntry(clsTimeEntry entryToDelete)
 {
     using (TimeCardContext context = new TimeCardContext())
     {
         clsTimeEntry entry = context.TimeCardEntries.FirstOrDefault(e => e.EntryID == entryToDelete.EntryID);
         if (entry == null)
         {
             throw new Exception(string.Format("Entry for EntryID \"{0}\" was not found.", entryToDelete));
         }
         context.TimeCardEntries.Remove(entry);
         context.SaveChanges();
     }
 }
Exemple #14
0
 public void UpdateEntry(clsTimeEntry updatedEntry)
 {
     using (TimeCardContext context = new TimeCardContext())
     {
         DbEntityEntry <clsTimeEntry> entry = context.Entry(updatedEntry);
         if (entry == null)
         {
             context.TimeCardEntries.Attach(updatedEntry);
             entry = context.Entry(updatedEntry);
         }
         entry.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
        public IEnumerable <EmployeeDTO> SearchEmployees(string firstName, string lastName, string title, bool includeTimeCards)
        {
            using (var context = new TimeCardContext())
            {
                var employees =
                    context.Employees.AsEnumerable().Where(
                        e =>
                        String.IsNullOrWhiteSpace(firstName) ||
                        e.FirstName.Equals(firstName, StringComparison.InvariantCultureIgnoreCase)).Where(
                        e =>
                        String.IsNullOrWhiteSpace(lastName) ||
                        e.LastName.Equals(lastName, StringComparison.InvariantCultureIgnoreCase)).Where(
                        e =>
                        String.IsNullOrWhiteSpace(title) ||
                        e.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase));

                return(employees.Select(e => e.ToDTO(includeTimeCards)).ToList());
            }
        }
Exemple #16
0
    public List <clsTimeEntry> GetAllEntries(DateTime beginDate, DateTime endDate)
    {
        using (TimeCardContext context = new TimeCardContext())
        {
            IQueryable <clsTimeEntry> query =
                from entry in context.TimeCardEntries
                where entry.DateWorked >= beginDate && entry.DateWorked <= endDate
                orderby entry.EntryID
                select entry;

            int count = query.Count();

            if (count > 500)
            {
                throw new clsTooManyRecordsException("More than 500 records found.");
            }

            return(query.ToList());
        }
    }
 public TimeCardController(ILogger <TimeCardController> logger, TimeCardContext timeCardRepository)
 {
     _logger             = logger;
     _timeCardRepository = timeCardRepository;
 }