示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var data = _con.Departments.SingleOrDefault(c => c.name == txt_department.Text.ToUpper());

            if (data == null)
            {
                var datas = new tbl_department
                {
                    name = txt_department.Text.ToUpper()
                };
                _con.Departments.Add(datas);
                _con.SaveChanges();
                MessageBox.Show("Saved Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Department Already Exist!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (MessageBox.Show("Want to Add more department?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Add_Department obj = new Add_Department(userName);
                obj.Show();
                this.Close();
            }
            else
            {
                FirstPage obj = new FirstPage(userName);
                obj.Show();
                this.Close();
            }
        }
示例#2
0
        public ActionResult Savedepartment(DepartmentVM model)
        {
            if (model.id == 0)
            {
                tbl_department deparment = new tbl_department();
                deparment.department_name = model.department_name.ToUpper();
                _departmentservice.CreateDepartment(deparment);
            }
            else
            {
                var findDep = _departmentservice.findDepartment(model.id);
                if (findDep == null)
                {
                    Warning("Department cannot be found", true);
                    return(View("EditDepartment"));
                }
                findDep.department_name = model.department_name;
                var success = _departmentservice.UpdateDepartment(findDep);
                if (success == true)
                {
                    Success("Department updated successfully!", true);
                    return(RedirectToAction("departments"));
                }
            }

            Success("Department created successfully");

            return(RedirectToAction("createdepartment"));
        }
 public void CreateDepartment(tbl_department department)
 {
     using (var scope = new TransactionScope())
     {
         _departmentrepository.insert(department);
         _departmentrepository.CommitChanges();
         scope.Complete();
     }
 }
        public bool UpdateDepartment(tbl_department department)
        {
            var success = false;

            if (department != null)
            {
                using (var scope = new TransactionScope())
                {
                    _departmentrepository.Update(department);
                    _departmentrepository.CommitChanges();
                    scope.Complete();
                    success = true;
                }
            }

            return(success);
        }