public bool Delete(DemandStatus demandStatus) { using (var DemandStatusRepository = _factory.GetRepository <DemandStatus>()) { return(DemandStatusRepository.Delete(demandStatus)); } }
public JsonResult Update(DemandStatus demandStatus) { using (var DemandStatusRepository = _factory.GetRepository <DemandStatus>()) { return(Json(DemandStatusRepository.Update(demandStatus))); } }
private IQueryable <DemandStatus> GetAllTest() { var list = new List <DemandStatus>(); DemandStatus a1 = new DemandStatus { Id = 1 }; DemandStatus a2 = new DemandStatus { Id = 2 }; list.Add(a1); list.Add(a2); return(list.AsQueryable()); }
public void Create2() { DemandStatus demandStatus = new DemandStatus() { Id = 1 }; var mock = new Mock <IRepository <DemandStatus> >(); mock.Setup(repo => repo.Create(demandStatus)); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <DemandStatus>()).Returns(mock.Object); _demandStatusController = new DemandStatusController(factoryMock.Object); //Assert.AreEqual(demandStatus, factoryMock); }
public void Create() { var memoryStore = new List <DemandStatus>(); DemandStatus demandStatusStub = new DemandStatus { Id = 1 }; var mock = new Mock <IRepository <DemandStatus> >(); mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable()); mock.Setup(repo => repo.Create(It.IsAny <DemandStatus>())).Returns((DemandStatus demandStatus) => { demandStatus.Id = 1; memoryStore.Add(demandStatus); return(demandStatus); }); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <DemandStatus>()).Returns(mock.Object); _demandStatusController = new DemandStatusController(factoryMock.Object); var emptyJson = _demandStatusController.GetAll(); Assert.IsNotNull(emptyJson); var emptyStore = emptyJson.Value as List <DemandStatus>; Assert.IsNotNull(emptyStore); Assert.AreEqual(emptyStore.Count, 0); var json = _demandStatusController.Create(demandStatusStub); Assert.IsNotNull(json); var result = json.Value as DemandStatus; Assert.NotNull(result); Assert.AreEqual(result.Id, 1); Assert.AreEqual(result.StatusName, demandStatusStub.StatusName); var notEmptyJson = _demandStatusController.GetAll(); Assert.IsNotNull(notEmptyJson); var notEmptyStore = notEmptyJson.Value as List <DemandStatus>; Assert.IsNotNull(notEmptyStore); Assert.AreEqual(notEmptyStore.Count, 1); }
/// <summary> /// Updates demand status with specified status value. /// </summary> /// <param name="conn"></param> /// <param name="demandId"></param> /// <param name="statusValue"></param> /// <returns></returns> public static bool UpdateDemandStatus(SqlConnection conn, int demandId, DemandStatus statusValue) { if (conn == null || demandId < -1) { return false; } SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@DemandId", demandId), new SqlParameter("@StatusValue", (int)statusValue) }; return DBHelper.SetDataToDB(conn, sp_UpdateDemandStatus, parameters); }
/// <summary> /// Updates demand status with specified status value. /// </summary> /// <param name="demandId"></param> /// <param name="statusValue"></param> /// <returns></returns> public bool UpdateDemandStatus(int demandId, DemandStatus statusValue) { bool result = false; var conn = DBHelper.GetSqlConnection(); try { conn.Open(); if (demandId > 0) { result = DemandDao.UpdateDemandStatus(conn, demandId, statusValue); } } catch (Exception e) { LogService.Log("更新需求状态失败", e.ToString()); } finally { conn.Close(); } return result; }