public async System.Threading.Tasks.Task <OperationResult <EquipmentOrder> > CreateEquipmentOrder(EquipmentOrder equipment) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <EquipmentOrder> >(() => { OperationResult <EquipmentOrder> result = new OperationResult <EquipmentOrder>(); try { Game game = GamesRepository.Read(equipment.GameId); if (game != null) { if (game.CreatorId == CurrentUser.Id || IsInCompany(game.CompanyId) || UserStore.IsInRole(CurrentUser, RoleNames.Admin)) { EquipmentOrder created = EquipmentOrdersRepository.CreateOrUpdate(equipment); if (created.Id > 0) { result.SingleResult = created; result.Result = true; } } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public ActionResult Add(int id) { int idret = id; List <Equipment> things = (List <Equipment>)TempData["Things"]; foreach (Equipment eq in things) { int code = 0; List <UserOrder> UserOrderList = new List <UserOrder>(); using (DBEntities db = new DBEntities()) { UserOrderList = db.UserOrder.ToList <UserOrder>(); if (UserOrderList.Count == 0) { code = 0; } if (UserOrderList.Count > 0) { code = UserOrderList.Max(x => x.Order_code) + 1; } UserOrder UO = new UserOrder(code, idret); db.UserOrder.Add(UO); db.SaveChanges(); EquipmentOrder order = new EquipmentOrder(eq.Code, UO.Order_code); db.EquipmentOrder.Add(order); db.SaveChanges(); } } return(RedirectToAction("Details", "Reservation", new { id = idret })); }
public void Search_Success() { List <EquipmentOrder> itemsToDelete = new List <EquipmentOrder>(); for (int i = 0; i < 5; i++) { EquipmentOrder item = new EquipmentOrder() { EquipmentId = _equipmentToDelete.Id, GameId = _gameToDelete.Id, Count = i + 1 }; itemsToDelete.Add(_equipmentOrdersRepository.CreateOrUpdate(item)); } var items = _equipmentOrdersRepository.Search("Count = @Count", new { PageSize = 10, PageNumber = 1, Count = 1 }); foreach (var item in itemsToDelete) { _equipmentOrdersRepository.Delete(item.Id); } Assert.AreNotEqual(0, items.Count()); Assert.AreEqual(1, items.FirstOrDefault().Count); }
public void Update_Value_Reseting_Value_Success() { EquipmentOrder order = new EquipmentOrder { EquipmentId = _equipmentToDelete.Id, GameId = _gameToDelete.Id, Count = 1 }; order = _equipmentOrdersRepository.CreateOrUpdate(order); Assert.IsNotNull(order); order.Count = 100; bool result = _equipmentOrdersRepository.Update(order); Assert.IsTrue(result); order = _equipmentOrdersRepository.Read(order.Id); _equipmentOrdersRepository.Delete(order.Id); Assert.IsTrue(order.Count == 100); }
public void GetAll_ReturnsResult_Success() { List <EquipmentOrder> certificatesToDelete = new List <EquipmentOrder>(); try { for (int i = 0; i < 20; i++) { EquipmentOrder eo = new EquipmentOrder() { EquipmentId = _equipmentToDelete.Id, GameId = _gameToDelete.Id, Count = 50 }; certificatesToDelete.Add(_equipmentOrdersRepository.CreateOrUpdate(eo)); } var certificates = _equipmentOrdersRepository.GetAll(15, 1); Assert.AreEqual(15, certificates.Count(), "Items count are not equal 15"); certificates = _equipmentOrdersRepository.GetAll(10, 2); // Second Page Assert.AreEqual(10, certificates.Count(), "Items count are not equal 10"); } finally { foreach (var certificate in certificatesToDelete) { _equipmentOrdersRepository.Delete(certificate.Id); } } }
public void CreateOrUpdate_Equipment_With_Equipment_Only_Throws() { EquipmentOrder equip = new EquipmentOrder() { EquipmentId = _equipmentToDelete.Id }; _equipmentOrdersRepository.CreateOrUpdate(equip); }
public void CreateOrUpdate_Certificate_Without_Count_Throws() { EquipmentOrder cert = new EquipmentOrder() { EquipmentId = _equipmentToDelete.Id, GameId = _gameToDelete.Id }; _equipmentOrdersRepository.CreateOrUpdate(cert); }
public int CreateOrUpdate_Create_Item_Success() { EquipmentOrder eo = new EquipmentOrder() { EquipmentId = _equipmentToDelete.Id, GameId = _gameToDelete.Id, Count = 50 }; var cer = _equipmentOrdersRepository.CreateOrUpdate(eo); Assert.IsNotNull(cer, "Certificate are not created"); return(cer.Id); }
public void GetEquipmentOrder_EquipmentOrderFound_ReturnCorrectEquipmentOrder() { var equipmentOrder = new EquipmentOrder(); var id = 1; unitOfWork.Setup(uow => uow.EquipmentOrders .GetEquipmentOrderWithTypeAndOrderStatus(eo => eo.Id == id)) .Returns(equipmentOrder); var response = controller.GetEquipmentOrder(id) as OkNegotiatedContentResult <EquipmentOrderDto>; var result = response.Content; Assert.IsNotNull(response); Assert.AreEqual(result, Mapper.Map <EquipmentOrder, EquipmentOrderDto>(equipmentOrder)); }
public void Update_Item_Success(int id) { EquipmentOrder item = _equipmentOrdersRepository.Read(id); Assert.IsNotNull(item); item.Count = 5; _equipmentOrdersRepository.CreateOrUpdate(item); var updatedCertificate = _equipmentOrdersRepository.Read(id); Assert.IsNotNull(updatedCertificate); Assert.AreEqual(item.Count, updatedCertificate.Count); }
// POST: api/EquipmentOrderApi public async System.Threading.Tasks.Task <IHttpActionResult> Post([FromBody] EquipmentOrder order) { if (order != null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SetPrincipal(); var result = await _manager.CreateEquipmentOrder(order); if (result.Result == true) { return(Ok(result.SingleResult)); } } return(BadRequest()); }
public static void Initialization(TestContext testContext) { _context = new DbContext(); _playgroundRepository = new PlaygroundsRepository(_context); _certificateRepository = new CertificateRepository(_context); _companiesRepository = new CompaniesRepository(_context); _equipmentsRepository = new EquipmentRepository(_context); _equipmentOrdersRepository = new EquipmentOrdersRepository(_context); _eventsRepository = new EventsRepository(_context); _gamesRepository = new GamesRepository(_context); _gameTypesRepository = new GameTypesRepository(_context); _newsRepository = new NewsRepository(_context); _operationsRepository = new OperationsRepository(_context); _tasksRepository = new TasksRepository(_context); _userStore = new UserStore <IdentityUser>(_context); _firstUser = _userStore.Users.FirstOrDefault(); _companyToDelete = _companiesRepository.CreateOrUpdate(new Company { Name = "TestCompanyName", Adress = "TestAdress", OwnerId = _firstUser.Id }); _firstUser.CompanyId = _companyToDelete.Id; _userStore.Update(_firstUser); _playgroundToDelete = _playgroundRepository.CreateOrUpdate(new Playground { CompanyId = _companyToDelete.Id, Name = "TestPlaygroundName", Price = 100 }); _certificateToDelete = _certificateRepository.CreateOrUpdate(new Certificate { FirstName = "TestCertificateFirstName", LastName = "TestCertificateLastName", StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), Price = 100, CompanyId = _companyToDelete.Id }); _equipmentToDelete = _equipmentsRepository.CreateOrUpdate(new Equipment { Name = "TestEquipmentName", Price = 100, Count = 50, CompanyId = _companyToDelete.Id }); _gameTypeToDelete = _gameTypesRepository.CreateOrUpdate(new GameType { Name = "TestGameTypeName", Price = 100, CompanyId = _companyToDelete.Id }); _gameToDelete = _gamesRepository.CreateOrUpdate(new Game { CreatorId = _firstUser.Id, BeginDate = DateTime.Now, GameType = _gameTypeToDelete.Id, Playground = _playgroundToDelete.Id, PlayerCount = 10, GamePrice = 100, CompanyId = _companyToDelete.Id }); _equipmentOrderToDelete = _equipmentOrdersRepository.CreateOrUpdate(new EquipmentOrder { GameId = _gameToDelete.Id, EquipmentId = _equipmentToDelete.Id, Count = 10 }); _eventToDelete = _eventsRepository.CreateOrUpdate(new Event { GameId = _gameToDelete.Id, CompanyId = _companyToDelete.Id, Title = "NewTestTitle", Description = "<p>New Description</p><p>New Test Description</p>" }); _newsToDelete = _newsRepository.CreateOrUpdate(new News { Title = "TestNewsTitle", PublishDate = DateTime.Now, Text = "TestNewsText", CompanyId = _companyToDelete.Id }); _operationToDelete = _operationsRepository.CreateOrUpdate(new Operation { Price = _gameToDelete.GamePrice, Date = DateTime.Now, CompanyId = _companyToDelete.Id, }); _taskToDelete = _tasksRepository.CreateOrUpdate(new Task { StaffId = _firstUser.Id, Text = "TestTaskText", CompanyId = _companyToDelete.Id, IsCompleted = false }); }
public void Update_Wrong_Argument_Throws() { EquipmentOrder cert = new EquipmentOrder(); _equipmentOrdersRepository.Update(cert); }
public void CreateOrUpdate_New_Certificate_Throws() { EquipmentOrder cert = new EquipmentOrder(); _equipmentOrdersRepository.CreateOrUpdate(cert); }
public ActionResult NewOrder(OrderViewModel orderItem) { var comment = ""; if (!String.IsNullOrEmpty(orderItem.Comment)) { comment = orderItem.Comment; } var orderBase = new OrderBase() { UserId = User.Identity.GetUserId(), DateFor = orderItem.DateFor, Grade = orderItem.Grade, Comment = comment }; _uow.GetRepository <OrderBase>().Add(orderBase); if (orderItem.IsEquipment == true) { var equipmentOrder = new EquipmentOrder() { UserId = User.Identity.GetUserId(), Name = orderItem.EquipmentName, Amount = orderItem.EquipmentAmount }; _uow.GetRepository <EquipmentOrder>().Add(equipmentOrder); } if (orderItem.IsSolid == true) { var solidOrder = new SolidOrder() { UserId = User.Identity.GetUserId(), Name = orderItem.ReagentName, Amount = orderItem.ReagentAmount, UnitId = orderItem.UnitId }; _uow.GetRepository <SolidOrder>().Add(solidOrder); } if ((orderItem.IsSolid == false) && (orderItem.IsEquipment == false)) { var solutionOrder = new SolutionOrder() { UserId = User.Identity.GetUserId(), Name = orderItem.ReagentName, Concentration = orderItem.Concentration, ConcentrationUnitId = orderItem.ConcentrationUnitId, Volume = orderItem.Volume }; _uow.GetRepository <SolutionOrder>().Add(solutionOrder); } _uow.SaveChanges(); return(RedirectToAction("NewItem", new { id = User.Identity.GetUserId() })); }
public void TestInitialization() { _companyToDelete = _manager.CompaniesRepository.CreateOrUpdate(new Company { Name = "TestCompanyName", Adress = "TestAdress", OwnerId = _firstUser.Id }); _firstUser.CompanyId = _companyToDelete.Id; _manager.UserStore.Update(_firstUser); _playgroundToDelete = _manager.PlaygroundsRepository.CreateOrUpdate(new Playground { CompanyId = _companyToDelete.Id, Name = "TestPlaygroundName", Price = 100 }); _certificateToDelete = _manager.CertificatesRepository.CreateOrUpdate(new Certificate { FirstName = "TestCertificateFirstName", LastName = "TestCertificateLastName", StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), Price = 100, CompanyId = _companyToDelete.Id }); _equipmentToDelete = _manager.EquipmentsRepository.CreateOrUpdate(new Equipment { Name = "TestEquipmentName", Price = 100, Count = 50, CompanyId = _companyToDelete.Id }); _gameTypeToDelete = _manager.GameTypesRepository.CreateOrUpdate(new GameType { Name = "TestGameTypeName", Price = 100, CompanyId = _companyToDelete.Id }); _gameToDelete = _manager.GamesRepository.CreateOrUpdate(new Game { CreatorId = _firstUser.Id, BeginDate = DateTime.Now, GameType = _gameTypeToDelete.Id, Playground = _playgroundToDelete.Id, PlayerCount = 10, GamePrice = 100, CompanyId = _companyToDelete.Id }); _equipmentOrderToDelete = _manager.EquipmentOrdersRepository.CreateOrUpdate(new EquipmentOrder { GameId = _gameToDelete.Id, EquipmentId = _equipmentToDelete.Id, Count = 10 }); _eventToDelete = _manager.EventsRepository.CreateOrUpdate(new Event { GameId = _gameToDelete.Id, CompanyId = _companyToDelete.Id }); _newsToDelete = _manager.NewsRepository.CreateOrUpdate(new News { Title = "TestNewsTitle", PublishDate = DateTime.Now, Text = "TestNewsText", CompanyId = _companyToDelete.Id }); _operationToDelete = _manager.OperationsRepository.CreateOrUpdate(new Operation { Price = _gameToDelete.GamePrice, Date = DateTime.Now, CompanyId = _companyToDelete.Id, }); _taskToDelete = _manager.TasksRepository.CreateOrUpdate(new Task { StaffId = _firstUser.Id, Text = "TestTaskText", CompanyId = _companyToDelete.Id, IsCompleted = false }); }