public bool Create(InterviewRequestVM irVM)
        {
            Company company = db.Companies.FirstOrDefault(com => com.Name == irVM.Company);

            if (company != null)
            {
                company.InterviewRequests.Add(new InterviewRequest
                {
                    Time     = irVM.Time,
                    Location = irVM.Location
                });
            }
            else
            {
                InterviewRequest ir = new InterviewRequest
                {
                    Time     = irVM.Time,
                    Location = irVM.Location
                };
                Company c = new Company
                {
                    Contact = irVM.Contact,
                    Name    = irVM.Company,
                    Email   = irVM.Email,
                    Phone   = irVM.Phone
                };
                db.Companies.Add(c);
                //Which one I think the second ?????
                db.InterviewRequests.Add(ir);
                c.InterviewRequests.Add(ir);
            }
            db.SaveChanges();
            return(true);
        }
Example #2
0
        public IActionResult Create(InterviewRequestVM irVM)
        {
            if (ModelState.IsValid)
            {
                //if (new InterviewRequestRepo(db).Create(irVM))
                Company company = db.Companies.FirstOrDefault(c => c.Name == irVM.Company);
                if (company != null)
                {
                    company.InterviewRequests.Add(new InterviewRequest
                    {
                        Time     = irVM.Time,
                        Location = irVM.Location
                    });
                }
                else
                {
                    Company com = new Company
                    {
                        Contact = irVM.Contact,
                        Email   = irVM.Email,
                        Name    = irVM.Company,
                        Phone   = irVM.Phone
                    };
                    InterviewRequest ir = new InterviewRequest
                    {
                        Time     = irVM.Time,
                        Location = irVM.Location
                    };
                    db.InterviewRequests.Add(ir);
                    db.Companies.Add(com);
                }

                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(View(irVM));
        }