Esempio n. 1
0
        public async Task <IActionResult> Create(Solution solution, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                solution.Added = DateTime.Now;

                var employeeID = int.Parse(HttpContext.Session.GetString("EmployeeId"));

                solution.EmployeeID = employeeID;

                if (TempData.ContainsKey("queryID"))
                {
                    solution.QueryID = (int)TempData["queryID"];
                }
                else
                {
                    return(RedirectToAction("Index", "Queries"));
                }

                _context.Solutions.Add(solution);
                await _context.SaveChangesAsync();

                if (file != null)
                {
                    var dir = _env.ContentRootPath + "\\FileUploads";

                    using (var filestream = new FileStream(Path.Combine(dir, file.FileName), FileMode.Create, FileAccess.Write))
                    {
                        await file.CopyToAsync(filestream);
                    }

                    //var solID = _context.Solutions
                    //    .Where(sol => (sol.EmployeeID == employeeID) && (sol.QueryID == (int)TempData["queryID"]))
                    //    .OrderByDescending(sol => sol.Added).ToList().FirstOrDefault();

                    var artifact = new Artifact();
                    artifact.Name       = file.FileName;
                    artifact.file       = Path.Combine(dir, file.FileName);
                    artifact.SolutionID = solution.ID;
                    artifact.Type       = file.FileName.Split(".").Last();

                    _context.Artifacts.Add(artifact);
                    await _context.SaveChangesAsync();
                }


                return(RedirectToAction(nameof(Index), new { queryID = (int)TempData["queryID"] }));
            }

            ViewData["EmployeeID"] = new SelectList(_context.Employees, "ID", "FName", solution.EmployeeID);
            ViewData["QueryID"]    = new SelectList(_context.Queries, "QueryID", "QueryID", solution.QueryID);
            return(View(solution));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(Query query)
        {
            if (ModelState.IsValid)
            {
                var employeeId = int.Parse(HttpContext.Session.GetString("EmployeeId"));
                query.Added      = DateTime.Now;
                query.EmployeeID = employeeId;
                query.QState     = States.pending;

                _context.Add(query);
                await _context.SaveChangesAsync();

                var employeeSubjects = _context.EmployeeSubjects
                                       .Include(es => es.Subject)
                                       .Include(es => es.Employee);

                var employees = employeeSubjects.Where(es => (int)es.Subject.Name == (int)query.Tag).ToList();

                foreach (var e in employees)
                {
                    if (e.EmployeeID != employeeId)
                    {
                        _context.EmployeeNotifications
                        .Add(new EmployeeNotification
                        {
                            EmployeeID   = e.EmployeeID,
                            QueryID      = query.QueryID,
                            Notification = query.Description
                        });
                    }
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(MyQueries)));
            }
            //ViewData["EmployeeID"] = new SelectList(_context.Employees, "ID", "FName", query.EmployeeID);
            return(View(query));
        }