Ejemplo n.º 1
0
 public TimeEntryViewModel(TimeEntry timeEntry)
 {
     Id = timeEntry.Id;
     Description = timeEntry.Description;
     Date = timeEntry.Date;
     Hours = timeEntry.Hours;
     Project = timeEntry.Project;
 }
Ejemplo n.º 2
0
        public ActionResult Edit(TimeEntryViewModel timeEntryViewModel)
        {
            if (timeEntryViewModel.Id > 0)
            {
                try
                {
                    //var timeEntyviewModel = new TimeEntryViewModel();

                    var timeEntryToUpdate = db.TimeEntries.First(i => i.Id == timeEntryViewModel.Id);

                    timeEntryToUpdate.Hours = timeEntryViewModel.Hours;
                    timeEntryToUpdate.Description = timeEntryViewModel.Description;
                    timeEntryToUpdate.Date = timeEntryViewModel.Date;
                    timeEntryToUpdate.Project = timeEntryViewModel.Project;

                    db.Entry(timeEntryToUpdate.Project).State = EntityState.Unchanged;
                    db.Entry(timeEntryToUpdate).State = EntityState.Modified;
                    db.SaveChanges();

                    return RedirectToAction("Index");


                }
                catch 
                {
                    return View();
                }
            }
            try
            {
                var timeEntryToSave = new TimeEntry();

                timeEntryToSave.Hours = timeEntryViewModel.Hours;
                timeEntryToSave.Description = timeEntryViewModel.Description;
                timeEntryToSave.Date = timeEntryViewModel.Date;
                timeEntryToSave.Project = timeEntryViewModel.Project;

                db.TimeEntries.Add(timeEntryToSave);
                db.Entry(timeEntryToSave.Project).State = EntityState.Unchanged;
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }

        }