Exemplo n.º 1
0
        public async void ProjectLogCheck <T>(int projId, T originalValue, T newValue, string field)
        {
            // needed the double check because of strings
            if (originalValue != null && newValue != null)
            {
                if (!EqualityComparer <T> .Default.Equals(originalValue, newValue))
                {
                    ProjectLog log = new ProjectLog
                    {
                        CreatedDate   = DateTime.Now,
                        FieldName     = field,
                        Id            = _context.ProjectLogs.Max(l => l.Id) + 1,
                        ModifiedDate  = DateTime.Now,
                        NewValue      = newValue.ToString(),
                        OriginalValue = originalValue.ToString(),
                        ProjectId     = projId,
                        UserId        = await _context.AppUsers.Where(u => u.ADName == User.Identity.Name).Select(u => u.Id).FirstOrDefaultAsync()
                    };
                    await _context.ProjectLogs.AddAsync(log);

                    await _context.SaveChangesAsync();
                }
            }
            else if (originalValue == null && newValue != null)
            {
                ProjectLog log = new ProjectLog
                {
                    CreatedDate   = DateTime.Now,
                    FieldName     = field,
                    Id            = _context.ProjectLogs.Max(l => l.Id) + 1,
                    ModifiedDate  = DateTime.Now,
                    NewValue      = newValue.ToString(),
                    OriginalValue = null,
                    ProjectId     = projId,
                    UserId        = await _context.AppUsers.Where(u => u.ADName == User.Identity.Name).Select(u => u.Id).FirstOrDefaultAsync()
                };
                await _context.ProjectLogs.AddAsync(log);

                await _context.SaveChangesAsync();
            }
            else if (newValue == null && originalValue != null)
            {
                ProjectLog log = new ProjectLog
                {
                    CreatedDate   = DateTime.Now,
                    FieldName     = field,
                    Id            = _context.ProjectLogs.Max(l => l.Id) + 1,
                    ModifiedDate  = DateTime.Now,
                    NewValue      = null,
                    OriginalValue = originalValue.ToString(),
                    ProjectId     = projId,
                    UserId        = await _context.AppUsers.Where(u => u.ADName == User.Identity.Name).Select(u => u.Id).FirstOrDefaultAsync()
                };
                await _context.ProjectLogs.AddAsync(log);

                await _context.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create([Bind("ID,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,Name,Surname,Address,Qualification,ContactNo,DepartmentID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.DepartmentID = new SelectList(_context.Department, "ID", "Name", employee.DepartmentID);

            return(View(employee));
        }