Beispiel #1
0
        private void AddParticipants(Discussion dis)
        {
            var eds = db.EmployeeDiscussions.Where(x => x.DiscussionId == dis.Id).ToList();

            foreach (var e in eds)
            {
                if (e.IsObserver)
                {
                    dis.Observer = new Employee()
                    {
                        FirstName = e.Employee.FirstName,
                        LastName = e.Employee.LastName,
                        IsObserver = e.IsObserver
                    };
                }
                else
                {
                    dis.Participants.Add(new Employee()
                    {
                        FirstName = e.Employee.FirstName,
                        LastName = e.Employee.LastName,
                        IsObserver = e.IsObserver
                    });
                }
            }
        }
Beispiel #2
0
        private void Initialize()
        {
            foreach (var d in db.Discussions)
            {
                var dis = new Discussion()
                {
                    Date = d.Date,
                    Id = d.Id,
                    Location = d.Location,
                    Outcome = d.Outcome,
                    Subject = d.Subject
                };

                AddParticipants(dis);
                this.Discussions.Add(dis);
            }
        }
Beispiel #3
0
        private void Initialize()
        {
            foreach (var d in db.Discussions)
            {
                var dis = new Discussion()
                {
                    Date     = d.Date,
                    Id       = d.Id,
                    Location = d.Location,
                    Outcome  = d.Outcome,
                    Subject  = d.Subject
                };

                AddParticipants(dis);
                this.Discussions.Add(dis);
            }
        }
Beispiel #4
0
        public ActionResult Create(CreateViewModel evm)
        {
            if (ModelState.IsValid)
            {
                var d = new Discussion();
                d.Date = evm.Date;
                d.Location = evm.Location;
                d.Outcome = evm.Outcome;
                d.Subject = evm.Subject;

                var ed1 = new EmployeeDiscussion();
                ed1.EmployeeId = evm.ObserverId;
                ed1.IsObserver = true;

                var ed2 = new EmployeeDiscussion();
                ed2.EmployeeId = evm.ParticipantId;
                ed2.IsObserver = false;

                try
                {

                    db.Entry(d).State = EntityState.Added;
                    db.SaveChanges();

                    db.Entry(ed1).State = EntityState.Added;
                    db.Entry(ed2).State = EntityState.Added;

                    ed1.DiscussionId = d.Id;
                    ed2.DiscussionId = d.Id;

                    db.SaveChanges();

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(ex.Message, "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            return View(evm);
        }