/**
         * Each metod sould go somthing like:
         * Console.WriteLine("Enter Department Name:");
         * string input = Console.ReadLine();
         * rins and repeat
         */
        public void Create()
        {
            Console.WriteLine("\nEnter department Name");
            var dname = Console.ReadLine();

            Console.WriteLine("\nEnter Manager SSN");
            var mgrSSN = Int32.Parse(Console.ReadLine());

            Console.Write("\nCreating Department...");

            try
            {
                var newDep = _repo.CreateDepartment(new Department {
                    DName = dname, MgrSSN = mgrSSN
                });


                if (newDep != null)
                {
                    Console.WriteLine("Done!");
                    PrintDepartment(newDep);
                }
                else
                {
                    Console.WriteLine("Failed!");
                    Console.WriteLine("Department is NULL");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed!");
                Console.WriteLine("Error: " + e.Message);
            }
        }
        public IActionResult CreateDepartment([FromBody] InputDepartment department)
        {
            _logger.Info("Create Department endpoint...", new { department });
            var tokenPayload = _accessTokenProvider.GetTokenPayload();

            if (tokenPayload != null)
            {
                if (tokenPayload.IsAdmin)
                {
                    int createdDepartmentId = _departmentRepository.CreateDepartment(department.DepartmentName);

                    if (createdDepartmentId > 0)
                    {
                        _logger.Info("Create Department endpoint successful!", new { createdDepartmentId });
                        return(Ok(new { createdDepartmentId }));
                    }

                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                return(StatusCode(StatusCodes.Status403Forbidden));
            }

            return(Unauthorized());
        }
Exemple #3
0
 public IActionResult Create(Department dept)
 {
     if (ModelState.IsValid)
     {
         dept.DepartmentId = (_departmentRepository.GetallDepartments().Count()) + 1;
         _departmentRepository.CreateDepartment(dept);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Exemple #4
0
        public IHttpActionResult CreateDepartment(Department department)
        {
            var NewDepartment = _repository.CreateDepartment(department);

            if (NewDepartment > 0)
            {
                return(Ok("Department Added successfully"));
            }
            else
            {
                return(Ok("Error while adding Department"));
            }
        }
        public async Task ShouldCreateOneDepartmentRecord()
        {
            var dept = new Department
            {
                Name      = "Test",
                GroupName = "Test Groupname"
            };

            await _deptRepo.CreateDepartment(dept);

            var result = _deptRepo.GetDepartmentByID(dept.DepartmentID);

            Assert.NotNull(result);
        }
Exemple #6
0
        public IActionResult Create(DepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                Department department = _mapper.Map <DepartmentViewModel, Department>(model);
                department.AddedBy = _admin.Fulname;

                _departmentRepository.CreateDepartment(department);

                return(RedirectToAction("index"));
            }

            return(View(model));
        }
Exemple #7
0
        public async Task <ActionResult> CreateDepartment([FromBody] Department department)
        {
            if (department == null)
            {
                return(BadRequest());
            }

            var aType = await _repository.CreateDepartment(department);

            if (aType == null)
            {
                return(Conflict());
            }

            return(CreatedAtAction(nameof(GetDepartment), new { id = department.Id }, department));
        }
 public ObjectResult CreateDepartment(Department dep)
 {
     if (_depRepo.CreateDepartment(dep))
     {
         return(new ObjectResult("Department succesfuly created")
         {
             StatusCode = 200
         });
     }
     else
     {
         return(new ObjectResult("Error while creating Department")
         {
             StatusCode = 500
         });
     }
 }
Exemple #9
0
        public async Task <Department> SaveDepartment(Department department)
        {
            var userId = _userContext.GetUserId();

            department.Modified     = DateTime.UtcNow;
            department.ModifiedById = userId;

            if (department.Id == default(long))
            {
                department.Created   = DateTime.UtcNow;
                department.CreatorId = userId;
                return(await _repository.CreateDepartment(department));
            }

            var dbDepartment = await _repository.GetDepartment(department.Id);

            dbDepartment.Name    = department.Name;
            dbDepartment.AdminId = department.AdminId;
            return(await _repository.UpdateDepartment(department));
        }
        public async Task <IActionResult> Register([FromBody] DepartmentRegDTO objDeparment)
        {
            _logger.LogInformation("Log message in the Register method Started");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await _repo.DepartmentExists(objDeparment.DepartmentName.ToLower()))
            {
                _logger.LogInformation("Log message in the Deparment Register Method already exist " + objDeparment.DepartmentName);
                return(BadRequest("Department Already Exist"));
            }
            var deptToCreate = _mapper.Map <Department>(objDeparment);

            var createDepart = await _repo.CreateDepartment(deptToCreate);

            //return StatusCode(201);
            var departToReturn = _mapper.Map <DepartmentDTO>(createDepart);

            return(CreatedAtRoute("GetDepartment", new { Controller = "Department", id = createDepart.DepartmentID }, departToReturn));
        }
Exemple #11
0
        public IActionResult CreateDepartment(DepartmentCreateDto departmentCreateDto)
        {
            if (departmentCreateDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_departmentRepo.isDepartmentExists(departmentCreateDto.Name))
            {
                ModelState.AddModelError("", "Department Exists!");
                return(StatusCode(404, ModelState));
            }

            var departmentObj = _mapper.Map <Department>(departmentCreateDto);

            if (!_departmentRepo.CreateDepartment(departmentObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {departmentObj.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetDepartment", new { departmentId = departmentObj.Id }, departmentObj));
        }
Exemple #12
0
 public async Task <DepartmentDto> CreateDepartment(DepartmentDto dep)
 {
     return(_mapper.Map <DepartmentDto>(await _repo.CreateDepartment(_mapper.Map <Department>(dep))));
 }
 public async Task <Department> Handle(CreateDepartmentCommand request, CancellationToken cancellationToken)
 {
     return(await _departmentRepository.CreateDepartment(request.Department));
 }
Exemple #14
0
 public Department CreateDepartment(Department department) =>
 _mapper.Map <Department>(_departmentRepository.CreateDepartment(_mapper.Map <DLL.Models.Department>(department)));
 public async Task <CreateDepartmentRes> CreateDepartment(CreateDepartmentReq request)
 {
     return(await _departmentRepository.CreateDepartment(request));
 }