Exemplo n.º 1
0
 public User GetById(Guid id)
 {
     using (HRMContext context = new HRMContext())
     {
         return(context.User.FirstOrDefault(x => x.UserId == id));
     }
 }
Exemplo n.º 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();
         }
     }
 }
Exemplo n.º 3
0
 public List <User> GetAll()
 {
     using (HRMContext context = new HRMContext())
     {
         return(context.User.ToList());
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 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();
        }
    }
Exemplo n.º 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
         });
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 13
0
 public EmployeeController(HRMContext context)
 {
     db = context;
 }
Exemplo n.º 14
0
 public Repository(HRMContext context)
 {
     DbContext = context;
     DbSet     = DbContext.Set <TEntity>();
 }
Exemplo n.º 15
0
 public UserRepository(UserManager <AppUser> userManager, IMapper mapper, HRMContext context) : base(context)
 {
     _userManager = userManager;
     _mapper      = mapper;
 }
Exemplo n.º 16
0
 public UnitOfWork(HRMContext context)
 {
     _context = context;
 }
Exemplo n.º 17
0
 public IndexModel(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Exemplo n.º 18
0
 public EmployeeRepository(HRMContext context)
     : base(context)
 {
 }
Exemplo n.º 19
0
 public EmployeeDetailsModel(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Exemplo n.º 20
0
 public EmployeesController(HRMContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Exemplo n.º 21
0
 public DeptController(HRMContext context)
 {
     _context = context;
 }
Exemplo n.º 22
0
 public static bool AministrativeareaExists(Guid id, HRMContext context)
 {
     return(context.Aministrativearea.Any(e => e.AdministrativeAreaId == id));
 }
 public AministrativeAreaService(HRMContext context)
 {
     _context = context;
 }