public async Task <IActionResult> Delete()
        {
            if (HttpContext.Session.GetString("eHashValue") != null &&
                HttpContext.Session.GetString("name") != null &&
                HttpContext.Session.GetString("stuId") != null)
            {
                var theApplicant = await GetExistApplicant();

                List <User> Users = _context.UserData
                                    .AsNoTracking()
                                    .OrderBy(u => u.stuId)
                                    .ToList();

                try
                {
                    User theUser = Users.Single(u => (u.stuId == theApplicant.stuId && u.name == theApplicant.name));
                    _context.UserData.Remove(theUser);
                }
                catch (Exception e)
                {
                }
                _context.AppliForm.Remove(theApplicant.appliForm);
                _context.Applicant.Remove(theApplicant);
                _context.SaveChanges();

                FileInfo photoFile    = new FileInfo(_hosting.WebRootPath + $@"\uploads\photos\{theApplicant.photoFileName}");
                FileInfo appendixFile = new FileInfo(_hosting.WebRootPath + $@"\uploads\appendices\{theApplicant.appliForm.appendixFileName}");

                if (photoFile.Exists)
                {
                    photoFile.Delete();
                }

                if (appendixFile.Exists)
                {
                    appendixFile.Delete();
                }
            }

            HttpContext.Session.Clear();
            return(View());
        }
Beispiel #2
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                JobPoster poster = new JobPoster()
                {
                    Name        = collection["Name"],
                    Salary      = Int32.Parse(collection["Salary"]),
                    Experience  = collection["Experience"],
                    Contract    = collection["Contract"],
                    Description = collection["Description"],
                    IsDeleted   = false
                };

                context.JobPosters.Add(poster);
                context.SaveChanges();

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