Exemple #1
0
        public async Task <IActionResult> NewJob(TwoThorJob job) // Blir kalt når en 2Thor trykker på ny jobb knappen i ShowChat (dvs _ChatNewJobPartial)
        {
            job.Completed     = "false";
            job.Reviewed      = "false";
            job.SubjectsKnown = new List <Subject>();
            job.TwoThorEmail  = User.Identity.Name;
            if (job.OtherName != null && job.JobSubject != null && job.Date != DateTime.MinValue && job.Time != DateTime.MinValue && job.Location != null)
            {
                _context.DbTwoThorJobList.Add(job); // jobben blir lagt til i databasen
                ChatMessage message = new ChatMessage(job.TwoThorEmail, job.OtherName,
                                                      job.TwoThorEmail.Substring(0, job.TwoThorEmail.IndexOf("@")) + " has scheduled an appointment in " + job.Location + " on " + job.Date.ToString().Substring(0, 10) + " at "
                                                      + job.Time.ToString().Substring(11, 2) + ":" + job.Time.ToString().Substring(14, 2) + " for the subject " + job.JobSubject + "!"); // det sendes en melding til chatten med informasjonen om møtet
                message.addTime();                                                                                                                                                       // meldingen blir timestampet
                _context.DbChatLog.Add(message);                                                                                                                                         // meldingen lagres i databasen
                await _context.SaveChangesAsync();                                                                                                                                       // databasen oppdateres

                return(RedirectToAction("ShowChat", new { chosenName = job.OtherName }));
            }
            return(RedirectToAction("ShowChat", new { chosenName = job.OtherName }));
        }
        public async Task <IActionResult> EditJob(TwoThorJob job, string Submit, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (job != null && Submit != null)
            {
                TwoThorJob tjob = null;
                job.TwoThorEmail = User.Identity.Name;
                foreach (TwoThorJob t in _context.DbTwoThorJobList)                                     // looper gjennom TwoThorsjobs for å finne jobben
                {
                    if (t.TwoThorEmail.Equals(User.Identity.Name) && t.OtherName.Equals(job.OtherName)) // hvis han/hun er det:
                    {
                        tjob = t;
                        break;
                    }
                }
                if (tjob.Completed.Equals("false") && tjob.Reviewed.Equals("false"))
                {
                    if (tjob != null && Submit.Equals("Delete"))
                    {
                        _context.DbChatLog.Add(new ChatMessage(tjob.TwoThorEmail, tjob.OtherName,
                                                               tjob.TwoThorEmail.Substring(0, tjob.TwoThorEmail.IndexOf("@")) + " has canceled/deleted your appointment on " + tjob.Date.ToString().Substring(0, 10) + " at " + tjob.Time.ToString().Substring(11, 2) + ":" + tjob.Time.ToString().Substring(14, 2) + "!"));
                        _context.DbTwoThorJobList.Remove(tjob);
                        await _context.SaveChangesAsync();
                    }
                    else if (tjob != null && Submit.Equals("Complete"))
                    {
                        tjob.Completed = "true";
                        tjob.Reviewed  = "false";
                        _context.DbChatLog.Add(new ChatMessage(tjob.TwoThorEmail, tjob.OtherName,
                                                               tjob.TwoThorEmail.Substring(0, tjob.TwoThorEmail.IndexOf("@")) + " has asked for a review for helping you with " + tjob.JobSubject));
                        await _context.SaveChangesAsync();
                    }
                }
                return(RedirectToAction("Profile", new { chosenName = User.Identity.Name }));
            }

            // If we got this far, something failed, send to front page
            return(RedirectToAction("Profile", "Account"));
        }