Esempio n. 1
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bbiDeleteUnit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                foreach (var rowHandle in gridView1.GetSelectedRows())
                {
                    var unitId = gridView1.GetRowCellValue(rowHandle, "UnitID");
                    if (unitId != null)
                    {
                        Unit unit = _unitService.GetUnitById(unitId.ToString());
                        if (unit != null)
                        {
                            try
                            {
                                _unitService.Delete(unitId.ToString());
                            }
                            catch (Exception ex)
                            {
                                MessageBoxHelper.ShowMessageBoxError(ex.Message);
                            }
                        }
                    }
                }
                LoadData();
            }
            else
            {
                EnableButtonUpdateAndDelete(false);
            }
        }
Esempio n. 2
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IUnitService, IUnitRepository>();
            var model         = new ApiUnitServerRequestModel();
            var validatorMock = new Mock <IApiUnitServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new UnitService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          validatorMock.Object,
                                          mock.DALMapperMockFactory.DALUnitMapperMock,
                                          mock.DALMapperMockFactory.DALCallAssignmentMapperMock,
                                          mock.DALMapperMockFactory.DALUnitOfficerMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <UnitDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 3
0
        /// <summary>
        /// Xóa đơn vị
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItemDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                foreach (var rowHandle in gridView1.GetSelectedRows())
                {
                    var unitId = gridView1.GetRowCellValue(rowHandle, "UnitID");
                    if (unitId != null)
                    {
                        Unit unit = _unitService.GetUnitById(unitId.ToString());
                        if (unit != null)
                        {
                            try
                            {
                                _unitService.Delete(unitId.ToString());
                            }
                            catch (Exception ex)
                            {
                                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                LoadUnits();
            }
            else
            {
                EnableButtonUpdateAndDelete(false);
            }

            //if (!string.IsNullOrEmpty(UnitId))
            //{
            //    Unit unit = _unitService.GetUnitById(UnitId);
            //    if (unit != null)
            //    {
            //        DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa thông tin Đơn Vị Tính : " + unit.UnitName + " không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            //        if (result == DialogResult.Yes)
            //        {
            //            try
            //            {
            //                _unitService.Delete(UnitId);
            //                LoadUnits();
            //            }
            //            catch (Exception ex)
            //            {
            //                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //            }

            //        }
            //    }
            //}
            //else
            //    XtraMessageBox.Show("Vui lòng chọn một Khu Vực cần sửa!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Esempio n. 4
0
        public ActionResult OnDelete(int id)
        {
            var result = UnitService.Delete(id);

            SetFlashMessage(result == Result.Ok ?
                            "Xóa đơn vị tính thành công." :
                            "Đơn vị tính không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public JsonResult Delete(Unit unit)
        {
            int result = unitService.Delete(unit.Id);

            if (result != 0)
            {
                return(Json(new { messageType = "success", note = AppGlobal.DeleteSuccessMessage }));
            }
            else
            {
                return(Json(new { messageType = "eror", note = AppGlobal.DeleteFailMessage }));
            }
        }
Esempio n. 6
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IUnitService, IUnitRepository>();
            var model = new ApiUnitServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new UnitService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UnitModelValidatorMock.Object,
                                          mock.DALMapperMockFactory.DALUnitMapperMock,
                                          mock.DALMapperMockFactory.DALCallAssignmentMapperMock,
                                          mock.DALMapperMockFactory.DALUnitOfficerMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.UnitModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <UnitDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 7
0
        /// <summary>
        ///     根据类型id查找关联它的表是否为0
        /// </summary>
        /// <param name="typeid">类型id</param>
        /// <param name="typename">类型名字</param>
        /// <returns></returns>
        public string GetRelationtById(long typeid, string typename)
        {
            var cureTypeService = new CureTypeService();
            var medicineService = new MedicineService();
            var unitService = new UnitService();
            var fodderTypeService = new FodderTypeService();
            var excetionTypeService = new ExceptionTypeService();
            var pigTypeService = new PigTypeService();
            var pigHouseTypeService = new PigHouseTypeService();
            var taskStatusTypeService = new TaskStatusTypeService();
            var taskTypeService = new TaskTypeService();
            var roleTypeService = new RoleTypeService();
            var preventionTypeService = new PreventionTypeService();
            var roleAuthorityService = new RoleAuthorityService();
            var customerService = new CustomerService();
            if (typeid == 0)
            {
                return "不存在于数据库,可以删除";
            }
            try
            {
                if (typename == "治疗")
                {
                    cureTypeService.Delete(cureTypeService.Find(typeid));
                }
                if (typename == "单位")
                {
                    unitService.Delete(unitService.Find(typeid));
                }
                if (typename == "药物")
                {
                    medicineService.Delete(medicineService.Find(typeid));
                }
                if (typename == "异常")
                {
                    excetionTypeService.Delete(excetionTypeService.Find(typeid));
                }
                if (typename == "饲料")
                {
                    fodderTypeService.Delete(fodderTypeService.Find(typeid));
                }
                if (typename == "生猪")
                {
                    if (pigTypeService.Find(typeid).Name == "母猪" || pigTypeService.Find(typeid).Name == "公猪")
                    {
                        return "不可删除";
                    }
                    pigTypeService.Delete(pigTypeService.Find(typeid));
                }
                if (typename == "防疫")
                {
                    preventionTypeService.Delete(preventionTypeService.Find(typeid));
                }
                if (typename == "猪舍")
                {
                    pigHouseTypeService.Delete(pigHouseTypeService.Find(typeid));
                }
                if (typename == "任务状态")
                {
                    if (taskStatusTypeService.Find(typeid).Name == "未完成" ||
                        taskStatusTypeService.Find(typeid).Name == "已完成" ||
                        taskStatusTypeService.Find(typeid).Name == "正在进行")
                    {
                        return "不可删除";
                    }
                    taskStatusTypeService.Delete(taskStatusTypeService.Find(typeid));
                }
                if (typename == "任务类型")
                {
                    if (taskTypeService.Find(typeid).Name == "喂饲" || taskTypeService.Find(typeid).Name == "防疫" ||
                        taskTypeService.Find(typeid).Name == "巡查" || taskTypeService.Find(typeid).Name == "治疗" ||
                        taskTypeService.Find(typeid).Name == "销售" || taskTypeService.Find(typeid).Name == "转栏" ||
                        taskTypeService.Find(typeid).Name == "添加生猪")
                    {
                        return "不可删除";
                    }
                    taskTypeService.Delete(taskTypeService.Find(typeid));
                }
                if (typename == "角色")
                {
                    foreach (role_authority c in roleAuthorityService.FindByRoleTypeId(typeid))
                        roleAuthorityService.Delete(roleAuthorityService.Find(c.Id));
                    roleTypeService.Delete(roleTypeService.Find(typeid));
                }
                if (typename == "客户名称")
                {
                    customerService.Delete(customerService.Find(typeid));
                }
            }
            catch (Exception)
            {
                return "不可删除";
            }

            return "";
        }
Esempio n. 8
0
 public ActionResult DeleteConfirmed(int id)
 {
     db.Delete(id);
     return(RedirectToAction("Index"));
 }
Esempio n. 9
0
 public IActionResult Delete(Guid id)
 {
     return(Ok(_unitService.Delete(id)));
 }