Esempio n. 1
0
        public Job Delete(long id)
        {
            Job job = db.Jobs.Find(id);

            if (job == null)
            {
                return(null);
            }

            db.Jobs.Remove(job);
            db.SaveChanges();
            return(job);
        }
Esempio n. 2
0
        private JobBoardContext CreateDbContext()
        {
            var jobs    = GetFakeData().AsQueryable();
            var options = new DbContextOptionsBuilder <JobBoardContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var context = new JobBoardContext(options);

            context.Jobs.AddRange(jobs);
            context.SaveChanges();
            return(context);
        }
Esempio n. 3
0
 public void Commit()
 {
     _context.SaveChanges();
 }
        public async Task <IActionResult> Upload(/*CandidateDetails request*/ CandidateViewModel request)
        {
            #region MyRegion
            //        // do other validations on your model as needed
            //        if (request.Resume.FilePath != null)
            //        {
            //            var uniqueFileName = GetUniqueFileName(request.Resume.FilePath);
            //            var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
            //            var filePath = Path.Combine(uploads, uniqueFileName);
            //            request.resu.CopyTo(new FileStream(filePath, FileMode.Create));

            //            //to do : Save uniqueFileName  to your db table
            //        }
            //        // to do  : Return something
            //        return RedirectToAction("Index", "Home");
            //    }
            //    private string GetUniqueFileName(string fileName)
            //    {
            //        fileName = Path.GetFileName(fileName);
            //        return Path.GetFileNameWithoutExtension(fileName)
            //                  + "_"
            //                  + Guid.NewGuid().ToString().Substring(0, 4)
            //                  + Path.GetExtension(fileName);
            //    }
            //}
            #endregion

            if (ModelState.IsValid)
            {
                //_context.Add(request);
                //await _context.SaveChangesAsync();
                ViewData["success"] = true;
                TempData["success"] = true;

                var Upload = request.Document;

                var uniqueFileName = GetUniqueFileName(Upload.FileName);
                var uploads        = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
                var filePath       = Path.Combine(uploads, uniqueFileName);

                //var file = Path.Combine(_environment.ContentRootPath, "uploads", Upload.FileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Upload.CopyToAsync(fileStream);
                }

                try
                {
                    using (var transaction = _context.Database.BeginTransaction())
                    {
                        var resume = new Resume()
                        {
                            FilePath = filePath
                        };
                        _context.Resume.Add(resume);

                        _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Resume ON;");
                        _context.SaveChanges();
                        _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Resume OFF;");
                        transaction.Commit();

                        if (!string.IsNullOrWhiteSpace(request.URL))
                        {
                            var link = new LinkedInProfiles()
                            {
                                ProfilrUrl = request.URL
                            };
                            _context.LinkedInProfiles.Add(link);
                        }
                        _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT LinkedInProfiles ON;");
                        _context.SaveChanges();
                        _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT LinkedInProfiles OFF;");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                var companyName = _context.CompanyDetails
                                  .Where(s => s.CompanyId == request.jobDetails.Compnay.CompanyId)
                                  .Select(s => s.CompanyName).FirstOrDefault();

                #region Old code
                //MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**"); // enter from email and to email

                //msg.Body = "<html><head><head><body>you got an email</body></html>"; //enter body here
                //msg.Subject = "strSubject"; // enter subject line here

                //msg.IsBodyHtml = true;
                //Attachment att = new Attachment(filePath);
                //msg.Attachments.Add(att);

                //SmtpClient cli = new SmtpClient("111.111.111.111", 25);
                //cli.Credentials = new NetworkCredential("nnnnnnn", "yyyyyy");
                //cli.Send(msg);
                //msg.Dispose();
                #endregion

                #region new code email

                //send email
                using (MailMessage mm = new MailMessage("*****@*****.**", "*****@*****.**")) // fromId, ToId
                {
                    mm.Subject = "IOT Waterloo Candidate Detail (Job Request)";
                    mm.Body    = request.FirstName + " " + request.LastName + " requesting for a job from " +
                                 companyName + "and here are the detials.";

                    Attachment attachment = new Attachment(Upload.OpenReadStream(), uniqueFileName);

                    mm.Attachments.Add(attachment);
                    mm.IsBodyHtml = true;

                    SmtpClient smtp = new SmtpClient();
                    smtp.Host      = "smtp.gmail.com";
                    smtp.EnableSsl = true;

                    NetworkCredential netwoekCred = new NetworkCredential("*****@*****.**", "iot123456$");
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials           = netwoekCred;
                    smtp.Port = 587;
                    smtp.Send(mm);
                }

                #endregion
            }

            //return Ok(new { Status = "Success" }); JobDetail/Details/8
            return(RedirectToAction("Details", "Talent", new { id = request.jobDetails.JobId }));
        }