Exemplo n.º 1
0
        private void AddDepartment_WithValidDepartment_ShouldInvokeRepository()
        {
            Department valid = new Department("Name");

            _service.AddDepartment(valid);

            _repositoryMock.Verify(x => x.Add(valid), Times.Once);
        }
Exemplo n.º 2
0
 public ActionResult Create(Department department)
 {
     if (ModelState.IsValid)
     {
         departmentService.AddDepartment(department);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(department));
     }
 }
Exemplo n.º 3
0
        // 呼叫service將資料新增至資料庫
        public void AddDepartment()
        {
            this._deptService = new DepartmentService(_deptModel);
            int error_flag = 0;

            if (this._deptModel.GetDepartmentID() == "" || this._deptModel.GetDepartmentName() == "" || this._deptModel.GetDepartmentManager() == "")
            {
                MessageBox.Show("尚有欄位為空白, 請重新確認是否填寫完畢!");
                error_flag = 1;
            }

            if (error_flag == 1)
            {
                return;
            }

            if (_deptService.AddDepartment())
            {
                MessageBox.Show("新增成功!");
            }
            else
            {
                MessageBox.Show("新增失敗!");
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                DepartmentService service = new DepartmentService();
                PopulateDepartmentObject();

                if (service.AddDepartment(department))
                {
                    MessageBox.Show("Department Added Successfully", "Status",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearForm();
                    txtName.Focus();
                    txtDescription.SelectAll();
                }
                else
                {
                    string msg = "";
                    foreach (Error error in service.Errors)
                    {
                        msg += error.Description + Environment.NewLine;
                    }
                    MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtName.Focus();
                    txtName.SelectAll();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Insert Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtName.Focus();
                txtName.SelectAll();
            }
        }
Exemplo n.º 5
0
        public IActionResult Add(Department department)
        {
            departmentService.AddDepartment(department);
            departmentService.SaveChanges();

            logger.LogInformation("{username} created department {departmentName}", User.FindFirst(ClaimTypes.Name).Value, department.Name);

            return(RedirectToAction(nameof(List)));
        }
Exemplo n.º 6
0
    public static int AddDepartment(string DepartmentName, string shortName)
    {
        using (DepartmentService DepartmentService = new DepartmentService())
        {
            Department objDepartment = new Department();
            objDepartment.DepartmentName = DepartmentName;
            objDepartment.ShortName      = shortName;

            return(DepartmentService.AddDepartment(objDepartment));
        }
    }
 public IActionResult CreateDepartment([FromBody] Department dprt)
 {
     if (_service.AddDepartment(dprt))
     {
         return(Ok(dprt));
     }
     else
     {
         return(BadRequest("there error"));
     }
 }
Exemplo n.º 8
0
 protected void Button1_Click1(object sender, EventArgs e)
 {
     if (DepartmentService.AddDepartment(text1.Text, TextBox2.Text, TextBox3.Text) != -1)
     {
         Response.Write("<script language=javascript>window.alert('添加科室成功');</script>");
         text1.Text    = "";
         TextBox2.Text = "";
         TextBox3.Text = "";
     }
     else
     {
         Response.Write("<script language=javascript>window.alert('该科室编号已存在,请输入其他编号!');</script>");
     }
 }
        public async Task <IActionResult> Create([Bind("Id,Name")] Department department)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Title"]          = "Create";
                ViewData["acao"]           = EnumStatusAcoes.CREATE;
                ViewData["acaoForm"]       = string.Format(nameof(Create));
                ViewData["ehModelInvalid"] = true;
                return(View(nameof(_ViewAcoes), department));
            }

            await _departmentService.AddDepartment(department);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 10
0
        public ActionResult Create(DepartmentViewModel model)
        {
            try
            {
                bool result = _departmentService.AddDepartment(model);

                if (result)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                return(View());
            }
        }
        //[HttpPost]
        public IActionResult SaveDepartment(string deptId, string name, int cpId)
        {
            int empId = Convert.ToInt32(HttpContext.Session.GetString("id"));

            if (HttpContext.Session.GetString("role") == EmployeeRole.STORESUPERVISOR || HttpContext.Session.GetString("role") == EmployeeRole.STOREMANAGER)
            {
                if (!(deptId != null && name != null))
                {
                    TempData["alertMsg"] = "Please enter all information";
                    return(RedirectToAction("AddDepartment"));
                }
                Department dept = new Department();
                dept.Id   = deptId;
                dept.Name = name;
                dept.CollectionPointId = cpId;
                ds.AddDepartment(empId, dept);
                TempData["alertMsg"] = "Department is successfully created!";
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction(HttpContext.Session.GetString("role"), "Home"));
        }
        public ActionResult Create(DepartmentViewModel model)
        {
            try
            {
                bool result = _DepartmentService.AddDepartment(model);
                if (result)
                {
                    Alert("Congratulations", "Department successfully added!", NotificationType.success);
                }
                else
                {
                    Alert("Error", "Department Failed to be added!", NotificationType.error);
                }
                return(RedirectToAction(nameof(Index)));

                throw new Exception();
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
 /// <summary>
 /// 保存部门表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="departmentEntity">机构实体</param>
 /// <returns></returns>
 public void AddDepartment(string keyValue, DepartmentEntity departmentEntity)
 {
     _departmentService.AddDepartment(keyValue, departmentEntity);
 }
Exemplo n.º 15
0
 public ActionResult Create(Department department)
 {
     departmentService.AddDepartment(department);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 16
0
 public static void AddDepartment(string name)
 {
     DepartmentService.AddDepartment(name);
 }