Example #1
0
        public void EnsureValidDataTest()
        {
            var departmentRequest = new DepartmentRequest
            {
                DisplayOrder       = 2,
                Module             = DepartmentModule.LiveChat,
                ParentDepartmentId = 2,
                Title                = "Title",
                Type                 = DepartmentType.Private,
                UserGroups           = new List <int>(),
                UserVisibilityCustom = false
            };

            Assert.DoesNotThrow(() => departmentRequest.EnsureValidData(RequestTypes.Create));
            Assert.DoesNotThrow(() => departmentRequest.EnsureValidData(RequestTypes.Update));
        }
        public async Task DepartmentsController_Post_NotNull_Ok()
        {
            DepartmentRequest request = new DepartmentRequest()
            {
            };

            _mockDepartmentService.Setup(e => e.PostAsync(request)).ReturnsAsync(new DepartmentNonRequest()
            {
            });

            var departmentController = new DepartmentsController(_mockDepartmentService.Object);

            var respon = await departmentController.Post(request);

            Assert.IsType <OkObjectResult>(respon);
        }
 public DepartmentRequestVM(DepartmentRequest dr)
 {
     this.RequestID             = dr.RequestID;
     this.DateCreated           = dr.DateCreated;
     this.RequestTypeID         = dr.RequestTypeID;
     this.RequestingUserID      = dr.RequestingUserID;
     this.RequestorGroupID      = dr.RequestorGroupID;
     this.RequesteeGroupID      = dr.RequesteeGroupID;
     this.DateAcknowledged      = dr.DateAcknowledged;
     this.AcknowledgingEmployee = dr.AcknowledgingEmployee;
     this.DateCompleted         = dr.DateCompleted;
     this.CompletedEmployee     = dr.CompletedEmployee;
     this.Subject = dr.Subject;
     this.Topic   = dr.Topic;
     this.Body    = dr.Body;
 }
        /// <summary>
        /// Creator: Ryan Morganti
        /// Created: 2020/02/13
        /// Approvor: Derek Taylor
        ///
        /// Method for pulling New Department Requests based on DepartmentIDs
        /// </summary>
        /// <remarks>
        /// Updator:
        /// Updated:
        /// Update:
        ///
        /// </remarks>
        /// <param name="deptID"></param>
        /// <returns></returns>
        public List <DepartmentRequest> SelectNewRequestsByDepartmentID(string deptID)
        {
            List <DepartmentRequest> requests = new List <DepartmentRequest>();

            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_select_new_requests_by_departmentID", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@DepartmentID", deptID);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DepartmentRequest newRequest = new DepartmentRequest();

                        newRequest.RequestID        = reader.GetInt32(0);
                        newRequest.DateCreated      = reader.GetDateTime(1);
                        newRequest.RequestTypeID    = reader.GetString(2);
                        newRequest.RequestingUserID = reader.GetInt32(3);
                        newRequest.RequestorGroupID = reader.GetString(4);
                        newRequest.RequesteeGroupID = reader.GetString(5);
                        newRequest.Subject          = reader.GetString(6);
                        newRequest.Topic            = reader.GetString(7);
                        newRequest.Body             = reader.GetString(8);

                        requests.Add(newRequest);
                    }
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(requests);
        }
Example #5
0
        public DepartmentResponse ValidateRequest(DepartmentRequest reqObjects)
        {
            DepartmentResponse response = new DepartmentResponse();

            response.departments = new Department[reqObjects.departments.Length];
            string message = "";

            for (int idx = 0; idx < reqObjects.departments.Length; idx++)
            {
                if (reqObjects.departments == null)
                {
                    message = ResponseConstants.InvalidRequest;
                }
                else if ((reqObjects.departments[idx].Code == null || reqObjects.departments[idx].Code == "") && (reqObjects.departments[idx].action.ToUpper() == "A" || reqObjects.departments[idx].action.ToUpper() == "E"))
                {
                    message = "Code " + ResponseConstants.Mandatory;
                }
                else if ((reqObjects.departments[idx].Name == null || reqObjects.departments[idx].Name == "") && (reqObjects.departments[idx].action.ToUpper() == "A" || reqObjects.departments[idx].action.ToUpper() == "E"))
                {
                    message = "Name " + ResponseConstants.Mandatory;
                }
                else if ((reqObjects.departments[idx].Id == null || reqObjects.departments[idx].Id == "") && (reqObjects.departments[idx].action.ToUpper() == "E" || reqObjects.departments[idx].action.ToUpper() == "D"))
                {
                    message = "Id " + ResponseConstants.Mandatory;
                }
                Department proxyResponse = new Department();
                proxyResponse             = reqObjects.departments[idx];
                proxyResponse.message     = message;
                response.departments[idx] = proxyResponse;
                if (message != "")
                {
                    response.message = "Invalid Request";
                }
            }
            response.tui = reqObjects.tui;
            if (response.message == "" || response.message == null)
            {
                response.code = ResponseConstants.OK.ToString();
            }
            else
            {
                response.code = ResponseConstants.NotOK.ToString();
            }
            return(response);
        }
        private static RequestBodyBuilder PopulateRequestParameters(DepartmentRequest dept, RequestTypes requestType)
        {
            dept.EnsureValidData(requestType);

            RequestBodyBuilder parameters = new RequestBodyBuilder();

            if (!String.IsNullOrEmpty(dept.Title))
            {
                parameters.AppendRequestData("title", dept.Title);
            }

            parameters.AppendRequestData("type", EnumUtility.ToApiString(dept.Type));

            if (requestType == RequestTypes.Create)
            {
                parameters.AppendRequestData("module", EnumUtility.ToApiString(dept.Module));
            }

            if (dept.DisplayOrder > 0)
            {
                parameters.AppendRequestData("displayorder", dept.DisplayOrder);
            }

            if (dept.ParentDepartmentId > 0)
            {
                parameters.AppendRequestData("parentdepartmentid", dept.ParentDepartmentId);
            }

            if (dept.UserVisibilityCustom)
            {
                parameters.AppendRequestData("uservisibilitycustom", 1);
            }
            else
            {
                parameters.AppendRequestData("uservisibilitycustom", 0);
            }

            if (dept.UserGroups != null && dept.UserGroups.Count > 0)
            {
                parameters.AppendRequestDataArray <int>("usergroupid[]", dept.UserGroups);
            }

            return(parameters);
        }
Example #7
0
        /// <summary>
        /// Creator: Ryan Morganti
        /// Created: 2020/05/05
        /// Approver: Steve Coonrod
        ///
        /// Database Access method for inserting a new Request Record, and using it's
        /// Identity key as the primary key for the DepartmentRequest record.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        ///
        /// </remarks>
        /// <param name="request"></param>
        /// <returns></returns>
        public int InsertNewDepartmentRequest(DepartmentRequest request)
        {
            int result = 0;

            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_insert_request", conn);
            var cmd2 = new SqlCommand("sp_insert_new_department_request", conn);

            cmd.CommandType  = CommandType.StoredProcedure;
            cmd2.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@DateCreated", DateTime.Now);
            cmd.Parameters.AddWithValue("RequestTypeID", request.RequestTypeID);
            cmd.Parameters.AddWithValue("RequestingUserID", request.RequestingUserID);
            cmd.Parameters.AddWithValue("@Open", true);
            cmd.Parameters.Add("@RequestID", SqlDbType.Int).Direction = ParameterDirection.Output;

            try
            {
                conn.Open();
                cmd.ExecuteScalar();
                request.RequestID = (int)cmd.Parameters["@RequestID"].Value;


                cmd2.Parameters.AddWithValue("@DeptRequestID", request.RequestID);
                cmd2.Parameters.AddWithValue("@RequestingUserID", request.RequestingUserID);
                cmd2.Parameters.AddWithValue("@RequestGroupID", request.RequestorGroupID);
                cmd2.Parameters.AddWithValue("@RequestedGroupID", request.RequesteeGroupID);
                cmd2.Parameters.AddWithValue("@RequestTopic", request.Topic);
                cmd2.Parameters.AddWithValue("@RequestBody", request.Body);


                result = cmd2.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(result);
        }
Example #8
0
 public SuccessResponse Update(DepartmentRequest request)
 {
     try
     {
         var currentDepartment = _departmentRepository.FindBy(request.Id);
         currentDepartment.ThrowExceptionIfRecordIsNull();
         var departmentToCopy = TypeAdapter.Adapt <Department>(request);
         TypeAdapter.Adapt(departmentToCopy, currentDepartment);
         _departmentValidator.ValidateAndThrowException(currentDepartment, "Base");
         _departmentRepository.Update(currentDepartment);
         return(new SuccessResponse {
             IsSuccess = true
         });
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
Example #9
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns>返回值</returns>
        public int Update(DepartmentRequest request)
        {
            var result = 0;
            var model  = new Esmart_Sys_Departments();

            if (request != null)
            {
                model.DeparentId = request.DeparentId;
                model.CreateId   = request.CreateId;
                model.CreateTime = request.CreateTime;
                model.Name       = request.Name;
                model.ParentId   = request.ParentId;
                model.Remark     = request.Remark;
                model.SortNo     = request.SortNo;
                model.IsDelete   = request.IsDelete;
                result           = DepartmentDbAction.Update(model);
            }
            return(result);
        }
Example #10
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns>返回值</returns>
        public int Add(DepartmentRequest request)
        {
            var model = new Esmart_Sys_Departments();

            if (request != null)
            {
                model.DeparentId = request.DeparentId;
                model.CreateId   = request.CreateId;
                model.CreateTime = request.CreateTime;
                model.Name       = request.Name;
                model.ParentId   = request.ParentId;
                model.Remark     = request.Remark;
                model.SortNo     = request.SortNo;
                model.IsDelete   = request.IsDelete;
                DepartmentDbAction.Add(model);
                return(model.DeparentId);
            }
            return(-1);
        }
Example #11
0
        public void Update(
            int id,
            DepartmentRequest department)
        {
            if (department == null)
            {
                throw new ArgumentNullException(nameof(department));
            }
            var foundDepartment = _repository.GetById(id);

            if (foundDepartment == null)
            {
                throw new ArgumentNullException(nameof(foundDepartment));
            }

            foundDepartment.ShortName = department.ShortName;
            foundDepartment.LongName  = department.LongName;
            _repository.Update(foundDepartment);
        }
Example #12
0
        public Department Post([FromForm] DepartmentRequest request)
        {
            Console.WriteLine("department 1 :" + request.MinistryId);
            var date = DateTime.Now;

            var departmentdata = new Department
            {
                MinistryId  = request.MinistryId,
                Name        = request.Name,
                NameEN      = request.NameEN,
                ShortnameEN = request.ShortnameEN,
                ShortnameTH = request.ShortnameTH,
                CreatedAt   = date
            };

            _context.Departments.Add(departmentdata);
            _context.SaveChanges();
            Console.WriteLine("department 2 :" + request.Name);
            return(departmentdata);
        }
Example #13
0
        public async Task <IEnumerable <DepartmentDto> > GetDepartmentByKey(DepartmentRequest request)
        {
            var qry = $@"SELECT * FROM department 
                        where Deleted = 0 
                        {(!string.IsNullOrEmpty(request.DepartmentCode) ? "and DepartmentCode like @code" : "")}
                        {(!string.IsNullOrEmpty(request.DepartmentName) ? "and DepartmentName like @name" : "")}
                        {(!string.IsNullOrEmpty(request.Description) ? "and Description like @description" : "")}                        
                    ";

            var param = new DynamicParameters();

            param.Add("@code", "%" + request.DepartmentCode + "%");
            param.Add("@name", "%" + request.DepartmentName + "%");
            param.Add("@description", "%" + request.Description + "%");

            var result = await new DapperRepository <DepartmentDto>(_dbContextFactory.GetDbConnection(Global.DbConnection.HrisConnection))
                         .FromSqlAsync(qry, param);

            return(result);
        }
Example #14
0
        public async Task CreateDepartment(DepartmentRequest request)
        {
            try
            {
                _uow.BeginTransaction();

                var newData = _mapper.Map <Department>(request);
                newData.DepartmentId = Guid.NewGuid();
                newData.CreatedBy    = "Dummy";

                _departmentRepository.Insert(newData);
                _uow.CommitTransaction();

                await _uow.CommitAsync();
            }
            catch (Exception ex)
            {
                _uow.RollbackTransaction();
                throw ex;
            }
        }
Example #15
0
        /// <summary>
        /// Gets the departments.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public DepartmentResponse GetDepartments(DepartmentRequest request)
        {
            var response = new DepartmentResponse();

            if (request.LoadOptions.Contains("Departments"))
            {
                if (request.LoadOptions.Contains("IsActive"))
                {
                    response.Departments = DepartmentDao.GetDepartmentsByActive(true);
                }
                else
                {
                    response.Departments = DepartmentDao.GetDepartments();
                }
            }
            if (request.LoadOptions.Contains("Department"))
            {
                response.Department = DepartmentDao.GetDepartment(request.DepartmentId);
            }

            return(response);
        }
        public override Task <DepartmentModel> GetDepartmentInfo(DepartmentRequest request, ServerCallContext context)
        {
            DepartmentModel model = new DepartmentModel();

            try
            {
                using (DataContext dataContext = new DataContext(_dbConnection))
                {
                    var dept = dataContext.Departments.FirstOrDefault(x => x.Id == request.Id);
                    if (dept != null)
                    {
                        model.Id   = dept.Id;
                        model.Name = dept.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("DepartmentService.GetDepartmentInfo - Error: {0}", ex.Message);
            }
            return(Task.FromResult(model));
        }
Example #17
0
        public JsonResult SaveDepartment(DepartmentResponse model)
        {
            if (model.DeparentId == 0)
            {
                var req = new DepartmentRequest
                {
                    Name       = model.Name,
                    ParentId   = model.ParentId,
                    Remark     = model.Remark,
                    CreateTime = DateTime.Now,
                    CreateId   = CurrentUser.UserId,
                    IsDelete   = 0,
                };
                model.DeparentId = _departmentService.AddDepartment(req);
            }
            else
            {
                var resp = _departmentService.GetDepartmentResponse(model.DeparentId);
                var req  = new DepartmentRequest
                {
                    DeparentId = resp.DeparentId,
                    Name       = model.Name,
                    Remark     = model.Remark,
                    ParentId   = resp.ParentId,
                    CreateTime = resp.CreateTime,
                    CreateId   = resp.CreateId,
                    IsDelete   = resp.IsDelete ?? 0
                };
                _departmentService.UpdateDepartment(req);
            }

            var result = new ResponseModel <DepartmentResponse>
            {
                Body = model
            };

            return(Json(result));
        }
Example #18
0
        public void TestEditDepartmentRequestDetails()
        {
            // arrange
            int result;
            DepartmentRequest originalRequest = new DepartmentRequest
            {
                RequestID        = 100009,
                RequestingUserID = 100000,
                RequesteeGroupID = "Management",
                Topic            = "topic1",
                Body             = "Bodies everywhere"
            };
            string newGroupID = "Inventory";
            string newTopic   = "topic2";
            string newBody    = "body body";

            // act
            result = _requestManager.EditDepartmentRequestDetails(originalRequest.RequestingUserID, originalRequest.RequestID, originalRequest.RequesteeGroupID,
                                                                  originalRequest.Topic, originalRequest.Body, newGroupID, newTopic, newBody);

            // assert
            Assert.AreEqual(1, result);
        }
Example #19
0
        public async Task <ActionResult> Put(Guid id, DepartmentRequest dto)
        {
            await _mediator.Send(new UpdateCommand(id, dto));

            return(NoContent());
        }
 public ApiRequest CreateGetDepartmentTypes(string apiKey, DepartmentRequest properties)
 => CreateAddressGeneral(apiKey, "getWarehouseTypes", properties);
 public async Task <int> Update(DepartmentRequest request)
 {
     return(await _repository.ExecuteNonQuery("DepartmentUpdate", request));
 }
Example #22
0
        public async Task <List <DepartmentDto> > GetDepartments(DepartmentRequest request)
        {
            var data = await _departmentRepository.GetDepartmentByKey(request);

            return(data.ToList());
        }
        /// NAME: Hassan Karar
        /// DATE: 2020/2/7
        /// CHECKED BY: Derek Taylor
        /// <summary>
        ///  This method is creating event for Cot focus to the body of request response.
        /// </summary>
        /// <remarks>
        /// UPDATED BY:
        /// UPDATE DATE:
        /// WHAT WAS CHANGED:
        /// <param name="object"></param>
        /// <param name="e"></param>
        /// </remarks>

        private void btnOpenRecord_Click(object sender, RoutedEventArgs e)
        {
            DepartmentRequest department = new DepartmentRequest();


            //Authenticate
            if (null == cboDepartmentName.SelectedItem)
            {
                lblError.Content = "please choose a department";
                return;
            }
            if ((txtSubject.Text == "Subject") || ("" == txtSubject.Text))
            {
                lblError.Content = "Please enter the subject";
                return;
            }

            if ((txtBody.Text == "Inter The Body...") || ("" == txtBody.Text))
            {
                lblError.Content = "Please enter the body";
                return;
            }
            lblError.Content = "";


            if (null == cboRequestsID.SelectedItem)
            {
                lblError.Content = "please choose a RequestID";
                return;
            }

            if (null == cboUsersID.SelectedItem)
            {
                lblError.Content = "please choose the UserID";
                return;
            }


            //add to the bag
            department.DeptRequestID         = Convert.ToInt32(cboRequestsID.SelectedItem.ToString());
            department.RequesteeGroupID      = cboDepartmentName.SelectedItem.ToString();
            department.AcknowledgingEmployee = Convert.ToInt32(cboUsersID.SelectedItem.ToString());
            department.Subject = txtSubject.Text;
            department.Body    = txtBody.Text;
            try
            {
                if (neededRequest.addNewRequestIsPosted(department))
                {
                    txtBody.Select(0, 0);

                    txtResponse.Select(0, 0);

                    cboDepartmentName.SelectedItem = null;
                    cboUsersID.SelectedItem        = null;
                    cboRequestsID.SelectedItem     = null;
                    txtSubject.Clear();
                    txtBody.Clear();

                    lblError.Content = "the reqest added correctly";
                }
                else
                {
                    lblError.Content = "the reqest did not added correctly";
                    return;
                }
            }
            catch (Exception)
            {
                lblError.Content = " This Request is already choosen";
            }
        }
 public SuccessResponse Put(DepartmentRequest request)
 {
     return(_departmentService.Update(request));
 }
 public DepartmentResponse CreateDepartment(DepartmentRequest department)
 {
     this.ValidateDepartment(department);
     return(this.repository.CreateDepartment(
                new Department(department.Name)));
 }
 public CreateResponse Post(DepartmentRequest request)
 {
     return(_departmentService.Create(request));
 }
Example #27
0
        public FluentMockDepartmentRepository InsertAsync(DepartmentRequest request)
        {
            Setup(x => x.InsertAsync(request)).ReturnsAsync(1);

            return(this);
        }
Example #28
0
        public async Task <ActionResult> Post(DepartmentRequest dto)
        {
            await _mediator.Send(new CreateCommand(dto));

            return(NoContent());
        }
Example #29
0
        /// <summary>
        /// Sets the departments.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public DepartmentResponse SetDepartments(DepartmentRequest request)
        {
            var response = new DepartmentResponse();

            var departmentEntity = request.Department;

            if (request.Action != PersistType.Delete)
            {
                if (!departmentEntity.Validate())
                {
                    foreach (string error in departmentEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
            }
            try
            {
                if (request.Action == PersistType.Insert)
                {
                    var departments = DepartmentDao.GetDepartmentsByDepartmentCode(departmentEntity.DepartmentCode);
                    if (departments.Count > 0)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = @"Mã phòng ban " + departmentEntity.DepartmentCode + @" đã tồn tại !";
                        return(response);
                    }
                    AutoNumberListDao.UpdateIncreateAutoNumberListByValue("Department");
                    departmentEntity.DepartmentId = DepartmentDao.InsertDepartment(departmentEntity);
                    response.Message = null;
                }
                else if (request.Action == PersistType.Update)
                {
                    response.Message = DepartmentDao.UpdateDepartment(departmentEntity);
                }
                else
                {
                    var departmentForUpdate = DepartmentDao.GetDepartment(request.DepartmentId);
                    response.Message = DepartmentDao.DeleteDepartment(departmentForUpdate);
                }
            }
            catch (Exception ex)
            {
                response.Acknowledge = AcknowledgeType.Failure;
                response.Message     = ex.Message;
                return(response);
            }
            response.DepartmentId = departmentEntity != null ? departmentEntity.DepartmentId : 0;
            if (response.Message == null)
            {
                response.Acknowledge  = AcknowledgeType.Success;
                response.RowsAffected = 1;
            }
            else
            {
                response.Acknowledge  = AcknowledgeType.Failure;
                response.RowsAffected = 0;
            }

            return(response);
        }
        public void CreateUpdateDeleteDepartment()
        {
            Department dummyData = TestData;

            Department createdDept = TestSetup.KayakoApiService.Departments.CreateDepartment(DepartmentRequest.FromResponseData(dummyData));

            Assert.IsNotNull(createdDept);
            dummyData.Id = createdDept.Id;
            CompareDepartments(dummyData, createdDept);

            dummyData.Title                = "Updated Title";
            dummyData.Type                 = DepartmentType.Private;
            dummyData.DisplayOrder         = 34;
            dummyData.UserVisibilityCustom = false;
            dummyData.UserGroups           = new List <int>();

            Department updatedDept = TestSetup.KayakoApiService.Departments.UpdateDepartment(DepartmentRequest.FromResponseData(dummyData));

            Assert.IsNotNull(updatedDept);
            CompareDepartments(dummyData, updatedDept);

            bool success = TestSetup.KayakoApiService.Departments.DeleteDepartment(updatedDept.Id);

            Assert.IsTrue(success);
        }