コード例 #1
0
        public List <Employees> GetList(EmployeesRole employeesRole)
        {
            string cachekey = string.Concat(CacheKeys.Employees.StartsWith, "GetList-", employeesRole.Id);

            var allCat = _cacheService.Get <List <Employees> >(cachekey);

            if (allCat == null)
            {
                var Cmd = _context.CreateCommand();

                Cmd.CommandText = "SELECT * FROM  [Employees] WHERE RoleId = @RoleId";
                Cmd.Parameters.Add("RoleId", SqlDbType.UniqueIdentifier).Value = employeesRole.Id;

                DataTable data = Cmd.findAll();
                Cmd.Close();

                if (data == null)
                {
                    return(null);
                }

                allCat = new List <Employees>();

                foreach (DataRow it in data.Rows)
                {
                    allCat.Add(DataRowToEmployees(it));
                }

                _cacheService.Set(cachekey, allCat, CacheTimes.OneHour);

                //_cacheService.ClearStartsWith(string.Concat(CacheKeys.Category.StartsWith, "GetList-"));
            }
            return(allCat);
        }
コード例 #2
0
        public void Del(EmployeesRole emp)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "DELETE FROM [EmployeesRole] WHERE Id = @Id";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = emp.Id;

            Cmd.command.ExecuteNonQuery();
            Cmd.cacheStartsWithToClear(CacheKeys.EmployeesRole.StartsWith);
            Cmd.Close();
        }
コード例 #3
0
        public void Del(EmployeesRole emp)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "DELETE FROM [EmployeesRole] WHERE Id = @Id";

            Cmd.AddParameters("Id", emp.Id);

            Cmd.command.ExecuteNonQuery();
            Cmd.cacheStartsWithToClear(CacheKeys.EmployeesRole.StartsWith);
            Cmd.Close();
        }
コード例 #4
0
        private EmployeesRole DataRowToEmployeesRole(DataRow data)
        {
            if (data == null)
            {
                return(null);
            }

            var cat = new EmployeesRole();

            cat.Id          = new Guid(data["Id"].ToString());
            cat.Name        = data["Name"].ToString();
            cat.Description = data["Description"].ToString();

            return(cat);
        }
コード例 #5
0
        public void Update(EmployeesRole role)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "UPDATE [dbo].[EmployeesRole] SET [Name] = @Name, [Description] = @Description WHERE [Id] = @Id";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = role.Id;
            Cmd.AddParameters("Name", role.Name);
            Cmd.AddParameters("Description", role.Description);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.EmployeesRole.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Update EmployeesRole false");
            }
        }
コード例 #6
0
        public void Add(EmployeesRole role)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [EmployeesRole]([Id],[Name],[Description])"
                              + " VALUES(@Id,@Name,@Description)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = role.Id;
            Cmd.AddParameters("Name", role.Name);
            Cmd.AddParameters("Description", role.Description);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.EmployeesRole.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add EmployeesRole false");
            }
        }
コード例 #7
0
        public ActionResult CreateRole(CreateEditEmployeesRoleViewModel modelView)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var emp = new EmployeesRole
                        {
                            Name        = modelView.Name,
                            Description = modelView.Description
                        };

                        _employeesRoleService.Add(emp);

                        unitOfWork.Commit();
                        // We use temp data because we are doing a redirect
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Thêm chức vụ nhân viên thành công!",
                            MessageType = GenericMessages.success
                        };

                        return(RedirectToAction("ListRole"));
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex.Message);
                        ModelState.AddModelError("", "Có lỗi xảy ra khi thêm chức vụ!");
                    }
                }
            }

            return(View(modelView));
        }