public void CreateNewReading() { InitializeAllDevelopmentInstances(); // initialize the persistance layer and nhibernate engine . This is very very must to do. // Arrange Guid systemSession = DevelopmentManagerFactory.GetSystemSession(); IDevelopmentManager developmentManager = DevelopmentManagerFactory.GetDevelopmentManager(systemSession); WindSpeedDao speedDao = new WindSpeedDao { City = "Bengaluru", State = "Karnataka", StationCode = "KA-BE-03", ActualSpeed = 6, PredictedSpeed = 12, Date = DateTime.Now, Variance = -6 }; // Act int result = developmentManager.CommonManager.CreateNewReading(speedDao); // Assert Assert.IsNotNull(result); //test case for make sure that data save successfully Assert.AreNotEqual(0, result); // test case to make sure that new id returned or not }
public ServiceResponse CreateNewReading(Reading model) { result = new ServiceResponse(); try { if (ModelState.IsValid) { if (HttpRequestMessageExtensions.GetCookie(Request, "Wnreg") == model.Captcha) // validate the CAPTCHA { WindSpeedDao speedDao = new WindSpeedDao { City = model.City, State = model.State, StationCode = model.StationCode, ActualSpeed = model.ActualSpeed, PredictedSpeed = model.PredictedSpeed, Date = model.ReadingDate, Variance = model.Variance }; Guid systemSession = DevelopmentManagerFactory.GetSystemSession(); IDevelopmentManager developmentManager = DevelopmentManagerFactory.GetDevelopmentManager(systemSession); result.StatusCode = (int)HttpStatusCode.OK; result.Response = developmentManager.CommonManager.CreateNewReading(speedDao); } else { result.StatusCode = (int)HttpStatusCode.Forbidden; result.Response = 0; } } else { result.StatusCode = (int)HttpStatusCode.BadRequest; result.Response = 0; } } catch { result.StatusCode = (int)HttpStatusCode.MethodNotAllowed; result.Response = 0; } return result; }
public int CreateNewReading(CommonManagerProxy proxy, WindSpeedDao speedDao) { try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { tx.PersistenceManager.UserRepository.Save<WindSpeedDao>(speedDao); tx.Commit(); } return speedDao.Id; } catch (DBConcurrencyException ex) { return 0; } catch (Exception ex) { LogError(proxy, ex); return 0; } }
public int CreateNewReading(WindSpeedDao speedDao) { return CommonManager.Instance.CreateNewReading(this, speedDao); }