public User GetById(Guid id)
 {
     using (HRMContext context = new HRMContext())
     {
         return(context.User.FirstOrDefault(x => x.UserId == id));
     }
 }
Beispiel #2
0
 public static void WriteErrorLog(ErrorLog errorLog)
 {
     try
     {
         if (errorLog.ErrorMessage.Length > 1023)
         {
             errorLog.ErrorMessage = errorLog.ErrorMessage.Substring(0, 1000);
         }
         using (HRMContext db = new HRMContext())
         {
             errorLog.Id         = Guid.NewGuid();
             errorLog.CreateDate = DateTime.UtcNow;
             db.ErrorLogs.Add(errorLog);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         using (var db = new HRMContext())
         {
             var log = new ErrorLog();
             log.Id           = Guid.NewGuid();
             log.CreateDate   = DateTime.UtcNow;
             log.ErrorFor     = "Exception to write error log";
             log.ErrorFrom    = "WriteErrorLog";
             log.ErrorMessage = ex.Message.Length > 1023 ? ex.Message.Substring(0, 1000) : ex.Message;
             db.ErrorLogs.Add(log);
             db.SaveChanges();
         }
     }
 }
 public List <User> GetAll()
 {
     using (HRMContext context = new HRMContext())
     {
         return(context.User.ToList());
     }
 }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,ActiveStatus")] Role role)
        {
            if (ModelState.IsValid)
            {
                role.Id = Guid.NewGuid();
                db.Roles.Add(role);
                db.SaveChanges();
                using (var insertDb = new HRMContext())
                {
                    RolePermission rolePermission = new RolePermission();

                    insertDb.RolePermissions.RemoveRange(db.RolePermissions.Where(r => r.RoleId == role.Id));

                    db.ModulePermissions.ToList().ForEach(mp =>
                    {
                        rolePermission = new RolePermission()
                        {
                            Id             = Guid.NewGuid(),
                            RoleId         = role.Id,
                            ModuleId       = mp.ModuleId,
                            PermissionName = mp.PermissionName,
                            Permission     = false
                        };
                        insertDb.RolePermissions.Add(rolePermission);
                    });
                    insertDb.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
Beispiel #5
0
        public async Task <ActionResult <List <T> > > GetAllEntities()
        {
            using (HRMContext context = new HRMContext())
            {
                return(await context.Set <T>().ToListAsync());
            }

            //return await _context.Aministrativearea.ToListAsync();
        }
Beispiel #6
0
        /// <summary>
        /// Lấy 1 bản ghi theo ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult <T> > GetEntityByID(Guid id)
        {
            using (HRMContext context = new HRMContext())
            {
                var aministrativearea = await context.Set <T>().FindAsync(id);

                if (aministrativearea == null)
                {
                    return(null);
                }
                return(aministrativearea);
            }
        }
Beispiel #7
0
        //Tạo mới 1 bản ghi
        public async Task <ActionResult <bool> > CreateEntity <T1>(T1 tEntity) where T1 : class
        {
            using (HRMContext context = new HRMContext())
            {
                context.Set <T1>().Add(tEntity);
                var count = await context.SaveChangesAsync();

                if (count < 1)
                {
                    return(false);
                }
                return(true);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Chỉnh sửa 1 bản ghi theo id và thôgn tin mới
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="id"></param>
        /// <param name="tEntity"></param>
        /// <returns></returns>
        public async Task <ActionResult <bool> > ChangeAnEntityByID <T1>(Guid id, T1 tEntity) where T1 : class
        {
            using (HRMContext context = new HRMContext())
            {
                //Tim xem idz`
                context.Entry(tEntity).State = EntityState.Modified;
                var res = await context.SaveChangesAsync();

                if (res < 1)
                {
                    return(false);
                }
                return(true);
                //return new ActionServiceResult((int)HttpStatusCode.OK, true, "Cập nhật thành công");
            }
        }
        public AuthenticateResponse Authenticate(AuthenticateRequest model)
        {
            //Check thông tin request gửi lên xem có user nào có trùng usernaem và password nưh vậy không
            using (HRMContext context = new HRMContext())
            {
                var user = context.User.FirstOrDefault(x => x.Username == model.Username && x.Password == model.Password);
                // return null if user not found
                if (user == null)
                {
                    return(null);
                }

                // authentication successful so generate jwt token
                var token = generateJwtToken(user);

                return(new AuthenticateResponse(user, token));
            }
            //var user = _users.SingleOrDefault(x => x.Username == model.Username && x.Password == model.Password);
        }
Beispiel #10
0
    public static void Initialize(IServiceProvider serviceProvider)
    {
        using (var context = new HRMContext(
                   serviceProvider.GetRequiredService <DbContextOptions <HRMContext> >()))
        {
            // Check any employee exists
            if (context.Employees.Any())
            {
                return; // Data already exists no need to generate
            }

            context.Employees.AddRange(
                new Employee
            {
                Name        = "Md. Mahedee Hasan",
                Designation = "Head of Software Development",
                FathersName = "Yeasin Bhuiyan",
                MothersName = "Moriom Begum",
                DateOfBirth = new DateTime(1984, 12, 19, 00, 00, 00)
            },

                new Employee
            {
                Name        = "Khaleda Islam",
                Designation = "Software Engineer",
                FathersName = "Shahidul Islam",
                MothersName = "Momtaz Begum",
                DateOfBirth = new DateTime(1990, 10, 29, 00, 00, 00)
            },

                new Employee
            {
                Name        = "Tahiya Hasan Arisha",
                Designation = "Jr. Software Engineer",
                FathersName = "Md. Mahedee Hasan",
                MothersName = "Khaleda Islam",
                DateOfBirth = new DateTime(2017, 09, 17, 00, 00, 00)
            }
                );
            context.SaveChanges();
        }
    }
Beispiel #11
0
 public async static Task WriteAuditLog(AuditLog auditLog)
 {
     try
     {
         using (HRMContext db = new HRMContext())
         {
             auditLog.Id          = Guid.NewGuid();
             auditLog.LogDateTime = DateTime.UtcNow;
             db.AuditLogs.Add(auditLog);
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         WriteErrorLog(new ErrorLog()
         {
             ErrorFor     = "Writing Audit Log",
             ErrorFrom    = "Utility.WriteAuditLog",
             ErrorMessage = "Exception: " + ex.Message
         });
     }
 }
Beispiel #12
0
        public async Task <ActionResult <bool> > DeleteEntỉtyByID(Guid id)
        {
            using (HRMContext context = new HRMContext())
            {
                //Tìm xem bản ghi có trong DB hay không
                var aministrativearea = await context.Set <T>().FindAsync(id);

                if (aministrativearea == null)
                {
                    return(false);
                }

                context.Set <T>().Remove(aministrativearea);
                var resDelete = await context.SaveChangesAsync();

                if (resDelete < 1)
                {
                    return(false);
                }
                return(true);
            }
        }
Beispiel #13
0
 public EmployeeController(HRMContext context)
 {
     db = context;
 }
Beispiel #14
0
 public Repository(HRMContext context)
 {
     DbContext = context;
     DbSet     = DbContext.Set <TEntity>();
 }
Beispiel #15
0
 public UserRepository(UserManager <AppUser> userManager, IMapper mapper, HRMContext context) : base(context)
 {
     _userManager = userManager;
     _mapper      = mapper;
 }
Beispiel #16
0
 public UnitOfWork(HRMContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public IndexModel(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Beispiel #18
0
 public EmployeeRepository(HRMContext context)
     : base(context)
 {
 }
 public EmployeeDetailsModel(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Beispiel #20
0
 public EmployeesController(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public DeptController(HRMContext context)
 {
     _context = context;
 }
Beispiel #22
0
 public static bool AministrativeareaExists(Guid id, HRMContext context)
 {
     return(context.Aministrativearea.Any(e => e.AdministrativeAreaId == id));
 }
 public AministrativeAreaService(HRMContext context)
 {
     _context = context;
 }