예제 #1
0
        public ActionResult Index()
        {
            var customerQuery = from c in db.Customers orderby c.Name select c;
            ViewBag.CustomerId = new SelectList(customerQuery, "Id", "Name", null);
            var employeeQuery = from e in db.Employees orderby e.FirstName select e;
            ViewBag.EmployeeId = new SelectList(employeeQuery, "Id", "FullName", null);
            var taskQuery = from wt in db.WorkTasks orderby wt.Name select wt;
            ViewBag.TaskId = new SelectList(taskQuery, "Id", "DisplayFormat", null);

            ViewBag.latestTasks = db.TaskTimes.Where(_tt => !(_tt.End == null)).OrderByDescending(_tt => _tt.End);
            TaskTime homeModel = new TaskTime();

            homeModel.Start = DateTime.Now;
            return View(homeModel);
        }
예제 #2
0
        public async Task<IHttpActionResult> PutTaskTime(int id, TaskTime taskTime)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != taskTime.Id)
            {
                return BadRequest();
            }

            //TaskTime taskTimeToChange = db.TaskTimes.FirstOrDefault(_t => _t.Id == id);
            //taskTimeToChange.End = taskTime.End;
            //taskTimeToChange.Start = taskTime.Start;
            //taskTimeToChange.CustomerId = taskTime.CustomerId;
            //taskTimeToChange.Description = taskTime.Description;
            //taskTimeToChange.EmployeeId = taskTime.EmployeeId;
            //taskTimeToChange.Invoiced = taskTime.Invoiced;
            //taskTimeToChange.TaskId = taskTime.TaskId;
            db.Entry(taskTime).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskTimeExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #3
0
        public async Task<IHttpActionResult> PostTaskTime( TaskTime taskTime)
        {
            taskTime.Customer = null;
            taskTime.Employee = null;
            taskTime.Task = null;
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.TaskTimes.Add(taskTime);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = taskTime.Id }, taskTime);
        }