private void btnCreate_Click(object sender, EventArgs e)
        {
            DepartmentService departmentService = new DepartmentService();

            Department department = new Department(txtName.Text, txtDescription.Text, dtpInvocationDate.Value);

            string message = "";

            if (departmentService.CreateDepartment(department))
            {
                //message += $"Department Id: {department.DepartmentId} \n";
                message += $"Name: {department.Name}\n";
                message += $"Description: {department.Description}";

                MessageBox.Show(message, "Department Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                foreach (Error error in department.Errors)
                {
                    message += $"Error Code : {error.Code:000}\n Description: {error.Description}\n\n";
                }

                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public IHttpActionResult Post(DepartmentCreate teacher)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (!_departmentService.CreateDepartment(teacher))
     {
         return(InternalServerError());
     }
     return(Ok("Department created."));
 }
Ejemplo n.º 3
0
 public ActionResult Create(Department dept)
 {
     if (ModelState.IsValid)
     {
         DepartmentService service = new DepartmentService();
         service.CreateDepartment(dept);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(dept));
     }
 }
        public ActionResult CreateDepartment(Department dept, FormCollection form)
        {
            DepartmentService ds = new DepartmentService();

            ViewBag.CollectionPointList = collectionPointService.GetAllCollectionPoints();
            try
            {
                var PointID = Convert.ToInt32(form["PointID"]);

                dept.collectionPointID = PointID;
            }
            catch
            {
                string errorMessage = String.Format("Select Collection Point.");
                ModelState.AddModelError("collectionPointID", errorMessage);
                return(View());
            }



            string deptCode = dept.departmentCode;

            if (departmentService.isExistingCode(deptCode))
            {
                string errorMessage = String.Format("{0} has been used.", deptCode);
                ModelState.AddModelError("departmentCode", errorMessage);
            }
            else
            {
                try
                {
                    Boolean           b     = ds.CreateDepartment(dept);
                    List <Department> model = ds.GetAllDepartment();
                    return(RedirectToAction("ListDepartment"));
                }
                catch (Exception e)
                {
                    TempData["ExceptionMessage"] = e.Message;
                }
            }

            ViewBag.CollectionPointList = collectionPointService.GetAllCollectionPoints();


            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult CreateNew(Department department, string sessionId)
        {
            try
            {
                DepartmentService.CreateDepartment(department);

                List <Department> departments = DepartmentService.GetAllDepartment();
                ViewData["departments"] = departments;
            }
            catch (SqlException)
            {
                TempData["errorMsg"]  = "<script>alert('Department code already exists! Please verify.');</script>";
                ViewData["sessionId"] = sessionId;
                ViewData["empNames"]  = EmployeeDAO.GetAllEmployeeNames();
                return(View("Create"));
            }
            return(RedirectToAction("All", new { sessionid = sessionId }));
        }
Ejemplo n.º 6
0
        public IActionResult CreateDepartment(CreateDepartmentModel model)
        {
            var validationData = _service.ValidateCreateDepartment(User, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            using (var trans = context.Database.BeginTransaction())
            {
                var entity = _service.CreateDepartment(model);
                //log event
                var ev = _sysService.GetEventForCreateDepartment(
                    $"Admin {UserEmail} created a new department", User, entity);
                _sysService.CreateAppEvent(ev);
                //end log event
                context.SaveChanges();
                trans.Commit();
            }
            return(NoContent());
        }
Ejemplo n.º 7
0
        private static Department CreateDepartment(DepartmentService deptService, string deptName)
        {
            var department = deptService.CreateDepartment(deptName);

            return(department);
        }