Esempio n. 1
0
        /// <summary>
        /// Updates a storage site.
        /// </summary>
        /// <param name="site">Site to update.</param>
        /// <returns>Returns updated site.</returns>
        public StorageSite UpdateStorageSiteMasterData(Guid id, string name)
        {
            StorageSite site = GetStorageSiteOrThrowNotFoundException(id);

            site.Name = name;
            return(LocationsRepository.UpdateStorageSite(site));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new storage site.
        /// </summary>
        /// <param name="name">Name of the storage site to create.</param>
        /// <returns>Returns the newly created site.</returns>
        public StorageSite CreateStorageSite(string name)
        {
            StorageSite site = LocationsRepository.CreateStorageSite(name);

            Publish(site); // Notify environment data service of new site
            return(site);
        }
        public HttpResponseMessage EditSingleLocation(LocationModel location)
        {
            var locationRepo           = new LocationsRepository();
            var editSingleLocationInfo = locationRepo.UpdateLocation(location);

            return(Request.CreateResponse(HttpStatusCode.OK, editSingleLocationInfo));
        }
Esempio n. 4
0
        public ActionResult RemovePost(int id)
        {
            try
            {
                DbLocation location = GetLocationIfExistsAndUserHasAccess(id);
                if (location == null)
                {
                    return(RedirectToAction("Index"));
                }

                LocationsRepository locationsRepository = _unitOfWork.LocationsRepository;
                locationsRepository.Remove(location);

                TempData["AlertType"]    = "success";
                TempData["AlertMessage"] = "De locatie is verwijderd!";
            }
            catch
            {
                TempData["AlertType"]    = "danger";
                TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het verwijderen van de locatie!";

                return(View());
            }

            return(RedirectToAction("Index", "Locations"));
        }
Esempio n. 5
0
        public ActionResult Create()
        {
            using (SuppliersRepository suppliersRepository = new SuppliersRepository(CurrentUser.CompanyId))
                using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
                    using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                    {
                        ViewBag.RelatedInventoryItem = new SelectList(inventoryRepository.GetList("Orders_Items")
                                                                      .Select(x => new { Id = x.Id, InventarNumber = x.InventarNumber, Title = x.Orders_Items.Title, SubTitle = x.Orders_Items.SubTitle })
                                                                      .ToList()
                                                                      .Select(x => new SelectListItemDB()
                        {
                            Id = x.Id, Name = x.InventarNumber + " - " + x.Title + " " + x.SubTitle
                        })
                                                                      .OrderBy(x => x.Name)
                                                                      .ToList(), "Id", "Name");

                        if (locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count() == 0)
                        {
                            return(Error(Loc.Dic.error_no_location_exist));
                        }
                        ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                        ViewBag.Suppliers  = new SelectList(suppliersRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                    }

            return(View());
        }
Esempio n. 6
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId         = CurrentUser.CompanyId;
                inventory.AddedBy           = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate      = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if (inventoryRepository.Create(inventory))
                    {
                        return(RedirectToAction("Index"));
                    }
                    return(Error(Loc.Dic.Error_DatabaseError));
                }
            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return(View(inventory));
        }
Esempio n. 7
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId = CurrentUser.CompanyId;
                inventory.AddedBy = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if(inventoryRepository.Create(inventory))
                        return RedirectToAction("Index");
                    return Error(Loc.Dic.Error_DatabaseError);
                }

            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return View(inventory);
        }
        public HttpResponseMessage DisplayLocations()
        {
            var locationRepo     = new LocationsRepository();
            var displayLocations = locationRepo.GetLocations();

            return(Request.CreateResponse(HttpStatusCode.OK, displayLocations));
        }
        public HttpResponseMessage SingleLocation(int id)
        {
            var locationRepo    = new LocationsRepository();
            var displayLocation = locationRepo.GetSingleLocation(id);

            return(Request.CreateResponse(HttpStatusCode.OK, displayLocation));
        }
        public void TestCustomBatchPropValues()
        {
            // Prerequisite entities
            Plastic         pp   = PlasticsRepository.CreatePlastic("PP", "Polypropylene");
            Material        mat  = MaterialsRepository.CreateMaterial("mat", "manu", "manu-id", pp);
            StorageSite     site = LocationsRepository.CreateStorageSite("test_site");
            StorageArea     area = LocationsRepository.CreateStorageArea(site, "test_area");
            StorageLocation loc  = new StorageLocation()
            {
                StorageSiteId   = site.Id,
                StorageAreaId   = area.Id,
                StorageSiteName = site.Name,
                StorageAreaName = area.Name
            };
            CustomBatchProp prop1 = PropRepository.CreateCustomBatchProp("prop-1");
            CustomBatchProp prop2 = PropRepository.CreateCustomBatchProp("prop-2");

            // Create batch with custom prop values
            MaterialBatch batch = Repository.CreateMaterialBatch(mat, DateTime.Today.AddDays(17), loc, 42, 42, new Dictionary <Guid, string>()
            {
                { prop1.Id, "Ak Bars" },
                { prop2.Id, "Aloha" }
            }, false);

            Assert.Equal(2, batch.CustomProps.Count);

            // Test updating
            batch.CustomProps[prop1.Id] = "UPDATE TEST";
            Repository.UpdateMaterialBatch(batch);
            batch = Repository.GetMaterialBatch(batch.Id);
            Assert.Equal(2, batch.CustomProps.Count);
            Assert.Single(batch.CustomProps.Where(p => p.Value == "UPDATE TEST"));
        }
Esempio n. 11
0
 public Form1()
 {
     InitializeComponent();
     Context             = new GeoGrafijaEntities();
     LocationsRepository = new LocationsRepository(Context);
     UserRepository      = new UserRepository(Context);
 }
Esempio n. 12
0
 public RedirectToActionResult Locations(string locationName, string description, string dateEstablished)
 {
     location = new ImportantLocations();
     location.LocationName    = locationName;
     location.Description     = description;
     location.DateEstablished = dateEstablished;
     LocationsRepository.AddLocation(location);
     return(RedirectToAction("Locations"));
 }
Esempio n. 13
0
        public void HelperMethodAddClosingFileAddressAndLocation()
        {
            var addressesRepository = new AddressesRepository(_dbConn);

            addressesRepository.InsertAdress(UserId);
            AddressId = addressesRepository.GetAddressId(UserId);
            var locationsRepository = new LocationsRepository(_dbConn);

            locationsRepository.InsertLocation(CompanyId, AddressId, UserId);
            LocationId = locationsRepository.GetLocationId(CompanyId, AddressId, UserId);
        }
Esempio n. 14
0
 public UnitOfWork(LocationMasterContext context)
 {
     _context   = context;
     Locations  = new LocationsRepository(_context);
     Users      = new UserRepository(_context);
     Attraction = new AttractionRepository(_context);
     Ticket     = new BuyedTicketRepository(_context);
     Category   = new CategoryRepository(_context);
     Photo      = new PhotoRepository(_context);
     Review     = new ReviewRepository(_context);
 }
Esempio n. 15
0
        /// <summary>
        /// Attempts to get a storage site from the underlying repository and throws a <see cref="StorageSiteNotFoundException"/> if no matching site could be found.
        /// </summary>
        /// <param name="id">ID of the storage site to get.</param>
        /// <exception cref="StorageSiteNotFoundException">Thrown if no matching site could be found.</exception>
        /// <returns>Returns the storage site, if found.</returns>
        private StorageSite GetStorageSiteOrThrowNotFoundException(Guid id)
        {
            StorageSite site = LocationsRepository.GetStorageSite(id);

            // Check for site existence
            if (site == null)
            {
                throw new StorageSiteNotFoundException(id);
            }

            return(site);
        }
 public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var locations = repository.Get(1);
     // Act
     repository.Deactivate(locations);
     // Assert
     Assert.Equal(false, locations.Active);
 }
 public void Verify_Add_Should_AddTheEntityToTheContext()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(false, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var locations = new Location { Active = true, CustomKey = "SALVATORE-RAA", };
     // Act
     repository.Add(locations);
     // Assert
     mockSetLocations.Verify(x => x.Add(locations), Times.Once);
 }
        public void Verify_Get_ByKey_Should_ReturnTheCorrectLocation()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            // Act
            var locations = repository.Get("KING-STEPHEN");

            // Assert
            Assert.Equal("/TEST/KING-STEPHEN", locations.ApiDetailUrl);
        }
Esempio n. 19
0
        /// <summary>
        /// Updates a given area of a given storage site.
        /// </summary>
        /// <param name="siteId">ID of the site for which to update an area.</param>
        /// <param name="areaId">ID of the area to update.</param>
        /// <param name="areaName">Area name to update.</param>
        /// <returns>Returns the updated area.</returns>
        public StorageArea UpdateStorageArea(Guid siteId, Guid areaId, string areaName)
        {
            StorageSite site = GetStorageSiteOrThrowNotFoundException(siteId);
            StorageArea area = site.Areas.Where(a => a.Id == areaId).FirstOrDefault();

            if (area == null)
            {
                throw new StorageAreaNotFoundException(siteId, areaId);
            }
            area.Name = areaName;
            area      = LocationsRepository.UpdateStorageArea(area);
            return(area);
        }
        public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var locations   = repository.Get(1);

            // Act
            repository.Remove(locations);
            // Assert
            mockSetLocations.Verify(x => x.Remove((Location)locations), Times.Once);
        }
        public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var locations   = repository.Get(1);

            // Act
            repository.Deactivate(locations);
            // Assert
            Assert.Equal(false, locations.Active);
        }
Esempio n. 22
0
        public string AddFileToDraft(string fileName /*, string pdfFileName*/)
        {
            UploadFileForTest(fileName);
            var locationsRepository            = new LocationsRepository(_dbConn);
            var closingFileDocumentsRepository = new ClosingFileDocumentsRepository(_dbConn);
            //var locationId = locationsRepository.GetLocationId(CompanyId, AddressId, UserId);
            var documentTemplatesRepository = new DocumentTemplatesRepository(_dbConn);
            var documentTemplateId          = documentTemplatesRepository.GetDocumentTemplateId(CompanyId, LocationId);
            var documentTemplateFileGuid    = documentTemplatesRepository.GetDocumentTemplateFileGuid(CompanyId, LocationId);
            var documentTemplateFileName    = documentTemplatesRepository.GetDocumentTemplateFileName(CompanyId, LocationId) + DateTime.Now.ToString("MM_dd_yyyy hh_mm_ss tt");

            closingFileDocumentsRepository.InsertFileToDraft(ClosingFileId, documentTemplateId, CompanyId, LocationId, documentTemplateFileGuid, documentTemplateFileName);
            return(documentTemplateFileName);
        }
        public void Verify_Update_Should_SetTheEntityStateToModified()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var locations   = repository.Get(1);

            locations.ApiDetailUrl = "/TEST";
            // Act
            repository.Update(locations);
            // Assert
            mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once);
        }
Esempio n. 24
0
        public ActionResult Create(Location location)
        {
            if (ModelState.IsValid)
            {
                location.CompanyId = CurrentUser.CompanyId;
                using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
                {
                    locationsRepository.Create(location);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", location.CompanyId);
            return(View(location));
        }
        public void Verify_Add_Should_AddTheEntityToTheContext()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(false, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var locations   = new Location {
                Active = true, CustomKey = "SALVATORE-RAA",
            };

            // Act
            repository.Add(locations);
            // Assert
            mockSetLocations.Verify(x => x.Add(locations), Times.Once);
        }
Esempio n. 26
0
        public ActionResult Create(Location location)
        {
            if (ModelState.IsValid)
            {
                location.CompanyId = CurrentUser.CompanyId;
                using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
                {
                    locationsRepository.Create(location);
                }
                return RedirectToAction("Index");
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", location.CompanyId);
            return View(location);
        }
Esempio n. 27
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.locationLayout);

            deleteBtn = FindViewById <Button>(Resource.Id.deleteBtn);

            backBtn = FindViewById <ImageButton>(Resource.Id.backBtn);

            counDisplayertBtn = FindViewById <Button>(Resource.Id.counDisplayertBtn);

            linLyt = FindViewById <LinearLayout>(Resource.Id.linLyt);

            listLocation = FindViewById <ListView>(Resource.Id.listLocation);



            listLocation.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, LocationsRepository.DisplayTableContent());

            msg = Resources.GetText(Resource.String.clickInfo);
            if (savedInstanceState != null)
            {
                counter = savedInstanceState.GetInt("counter", 0);
            }
            else
            {
                counter = 0;
            }
            counDisplayertBtn.Text = $"{counter++} { msg}";
            clickInfo      = new Button(this);
            backBtn.Click += delegate
            {
                Intent intent = new Intent(this, typeof(LocationActivity));

                StartActivity(intent);
            };
            counDisplayertBtn.Click += delegate
            {
                counDisplayertBtn.Text = $"{counter++} { msg}";
            };

            deleteBtn.Click += (s, e) =>
            {
                LocationsRepository.DeleteContent();
                listLocation.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, Array.Empty <string>());
            };
        }
        public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations, true);
            var repository  = new LocationsRepository(mockContext.Object);
            var searchModel = new Mock <ILocationSearchModel>();
            // Act
            var locations = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray();

            // Assert
            Assert.Equal(1, locations.Length);
            Assert.Equal(2, locations[0].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", locations[0].MyApiDetailUrl);
            // Stephen King was filtered out because he was Inactive
        }
        public void Verify_List_Should_ReturnAListOfLocationsWithData()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            // Act
            var locations = repository.List.ToArray();

            // Assert
            Assert.Equal(2, locations.Length);
            Assert.Equal(1, locations[0].Id);
            Assert.Equal("/TEST/KING-STEPHEN", locations[0].ApiDetailUrl);
            Assert.Equal(2, locations[1].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", locations[1].ApiDetailUrl);
        }
Esempio n. 30
0
        public ActionResult EditPost(int id, LocationEditViewModel model)
        {
            try
            {
                DbLocation location = GetLocationIfExistsAndUserHasAccess(id);
                if (location == null)
                {
                    return(RedirectToAction("Index"));
                }

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (location == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                LocationsRepository locationsRepository = _unitOfWork.LocationsRepository;
                location.Name              = model.Name;
                location.Description       = model.Description;
                location.Organisation      = model.Organisation;
                location.PricePerDay       = model.PricePerDay;
                location.Capacity          = model.Capacity;
                location.AddressCity       = model.AddressCity;
                location.AddressNumber     = model.AddressNumber;
                location.AddressPostalCode = model.AddressPostalCode;
                location.AddressProvince   = model.AddressProvince;
                location.AddressStreet     = model.AddressStreet;
                locationsRepository.Update(location);

                TempData["AlertType"]    = "success";
                TempData["AlertMessage"] = "De aanpassingen zijn correct opgeslagen.";

                return(RedirectToAction("Edit", new { id = id }));
            }
            catch
            {
                TempData["AlertType"]    = "danger";
                TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het verwerken van de aanpassingen!";

                return(View(model));
            }
        }
Esempio n. 31
0
        public IEnumerable <StorageSiteOverview> GetSitesOverview()
        {
            List <StorageSiteOverview> overview = new List <StorageSiteOverview>();
            var sites = LocationsRepository.GetAllStorageSites();

            foreach (var site in sites)
            {
                overview.Add(new StorageSiteOverview()
                {
                    Site          = site,
                    Temperature   = EnvironmentalDataRepository.GetLatestValue(site, EnvironmentalFactor.Temperature).Value,
                    Humidity      = EnvironmentalDataRepository.GetLatestValue(site, EnvironmentalFactor.Humidity).Value,
                    TotalMaterial = BatchRepository.GetMaterialBatches(null, site.Id).Sum(b => b.Quantity)
                });
            }
            return(overview);
        }
Esempio n. 32
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.InventoryManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            IEnumerable <Location> locations;

            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                locations = locationsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                locations = Pagination(locations, page, sortby, order);

                return(View(locations.ToList()));
            }
        }
Esempio n. 33
0
 public UnitOfWork(DataContext context)
 {
     _context      = context;
     Users         = new UsersRepository(_context);
     Photos        = new PhotosRepository(_context);
     Groups        = new GroupsRepository(_context);
     Memberships   = new MembershipsRepository(_context);
     Auths         = new AuthRepository(_context);
     Comments      = new CommentsRepository(_context);
     Achievements  = new AchievementsRepository(_context);
     Cities        = new CitiesRepository(_context);
     Countries     = new CountriesRepository(_context);
     Locations     = new LocationsRepository(_context);
     Matchdays     = new MatchdaysRepository(_context);
     MatchStatuses = new MatchStatusesRepository(_context);
     Friends       = new FriendsRepository(_context);
     Messages      = new MessagesRepository(_context);
     Chats         = new ChatsRepository(_context);
 }
        public void Verify_Search_WithPaging_Should_ReturnAListOfLocationsWithDataMatchingSearchParameters()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var searchModel = new LocationSearchModel {
                Paging = new Paging {
                    Skip = 1, Take = 1
                }
            };
            // Act
            var locations = repository.Search(searchModel /*.Object*/).ToArray();

            // Assert
            Assert.Equal(1, locations.Length);
            Assert.Equal(2, locations[0].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", locations[0].ApiDetailUrl);
            // Stephen King was filtered out because he was Skipped
        }
Esempio n. 35
0
        public ActionResult Create()
        {
            using (SuppliersRepository suppliersRepository = new SuppliersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
            {
                ViewBag.RelatedInventoryItem = new SelectList(inventoryRepository.GetList("Orders_Items")
                                  .Select( x => new { Id = x.Id, InventarNumber = x.InventarNumber, Title = x.Orders_Items.Title, SubTitle = x.Orders_Items.SubTitle })
                                  .ToList()
                  .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.InventarNumber + " - " + x.Title + " " + x.SubTitle })
                  .OrderBy(x => x.Name)
                  .ToList(), "Id", "Name");

                if (locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count() == 0)
                    return Error(Loc.Dic.error_no_location_exist);
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                ViewBag.Suppliers = new SelectList(suppliersRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x=>x.Name).ToList(), "Id", "Name");
            }

            return View();
        }
Esempio n. 36
0
        public ActionResult AddToInventory(int id = 0)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Location> locations = null;
            AddToInventoryModel model = new AddToInventoryModel();

            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                order = orderRep.GetEntity(id, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");
                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_order_not_approved);

                locations = locationsRep.GetList().OrderBy(x => x.Name).ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);
            }

            model.OrderId = order.Id;
            model.OrderItems = order.Orders_OrderToItem.ToList();
            model.LocationsList = new SelectList(locations, "Id", "Name");
            return View(model);
        }
Esempio n. 37
0
        public ActionResult AddToInventory(AddToInventoryModel model)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Inventory> createdItems = new List<Inventory>();
            List<Location> locations;
            bool noCreationErrors = true;

            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(model.OrderId, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");

                if (order == null) return Error(Loc.Dic.error_order_get_error);
                if (order.WasAddedToInventory) return Error(Loc.Dic.error_order_was_added_to_inventory);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_invoice_not_scanned_and_approved);

                locations = locationsRep.GetList().ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);

                foreach (SplittedInventoryItem splitedItem in model.InventoryItems)
                {
                    if (!noCreationErrors) break;
                    if (!splitedItem.AddToInventory) continue;

                    int? itemId = splitedItem.ItemsToAdd[0].ItemId;
                    Orders_OrderToItem originalItem = order.Orders_OrderToItem.FirstOrDefault(x => x.Id == itemId);
                    bool isValidList = originalItem != null && splitedItem.ItemsToAdd.All(x => x.ItemId == itemId);

                    if (!isValidList) { noCreationErrors = false; break; }

                    if (splitedItem.ItemsToAdd.Count == 1)
                    {
                        Inventory listItem = splitedItem.ItemsToAdd[0];
                        if (!locations.Any(x => x.Id == listItem.LocationId)) return Error(Loc.Dic.error_invalid_form);

                        Inventory newItem = new Inventory()
                        {
                            AssignedTo = listItem.AssignedTo,
                            LocationId = listItem.LocationId,
                            Notes = listItem.Notes,
                            SerialNumber = listItem.SerialNumber,
                            Status = listItem.Status,
                            WarrentyPeriodStart = listItem.WarrentyPeriodStart,
                            WarrentyPeriodEnd = listItem.WarrentyPeriodEnd,
                            ItemId = originalItem.ItemId,
                            OrderId = order.Id,
                            CompanyId = CurrentUser.CompanyId,
                            IsOutOfInventory = false,
                            OriginalQuantity = originalItem.Quantity,
                            RemainingQuantity = originalItem.Quantity
                        };

                        if (!inventoryRep.Create(newItem)) { noCreationErrors = false; break; }
                        createdItems.Add(newItem);
                    }
                    else if (originalItem.Quantity == splitedItem.ItemsToAdd.Count)
                    {
                        foreach (var item in splitedItem.ItemsToAdd)
                        {
                            if (!locations.Any(x => x.Id == item.LocationId)) { noCreationErrors = false; break; }

                            item.ItemId = originalItem.ItemId;
                            item.OrderId = order.Id;
                            item.CompanyId = CurrentUser.CompanyId;
                            item.IsOutOfInventory = false;

                            if (!inventoryRep.Create(item)) { noCreationErrors = false; break; }
                            createdItems.Add(item);
                        }
                    }
                    else { noCreationErrors = false; break; }
                }

                if (!noCreationErrors)
                {
                    foreach (var item in createdItems)
                    {
                        inventoryRep.Delete(item.Id);
                    }

                    return Error(Loc.Dic.error_inventory_create_error);
                }

                order.WasAddedToInventory = true;
                order.LastStatusChangeDate = DateTime.Now;
                if (ordersRep.Update(order) == null) return Error(Loc.Dic.error_database_error);

                bool hasInventoryItems = model.InventoryItems.Any(x => x.AddToInventory);
                string notes = hasInventoryItems ? Loc.Dic.AddToInventory_with_inventory_items : Loc.Dic.AddToInventory_no_inventory_items;

                int? historyActionId = null;
                historyActionId = (int)HistoryActions.AddedToInventory;
                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value, notes);

                return RedirectToAction("PendingInventory");
            }
        }
 public void Verify_List_Should_ReturnAListOfLocationsWithData()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     // Act
     var locations = repository.List.ToArray();
     // Assert
     Assert.Equal(2, locations.Length);
     Assert.Equal(1, locations[0].Id);
     Assert.Equal("/TEST/KING-STEPHEN", locations[0].ApiDetailUrl);
     Assert.Equal(2, locations[1].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", locations[1].ApiDetailUrl);
 }
 public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var locations = repository.Get(1);
     // Act
     repository.Remove(locations);
     // Assert
     mockSetLocations.Verify(x => x.Remove((Location)locations), Times.Once);
 }
 public void Verify_Search_WithModifiedSince_Should_ReturnAListOfLocationsWithDataMatchingSearchParameters()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations, true);
     var repository = new LocationsRepository(mockContext.Object);
     var createDate = new System.DateTime(2015, 05, 28, 10, 45, 00).AddDays(1).AddMinutes(-1);
     //var searchModel = new Mock<ILocationSearchModel>();
     //searchModel.Setup(m => m.ModifiedSince).Returns(() => createDate);
     var searchModel = new LocationSearchModel { ModifiedSince = createDate };
     // Act
     var locations = repository.Search(searchModel/*.Object*/).ToArray();
     // Assert
     Assert.Equal(1, locations.Length);
     Assert.Equal(2, locations[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", locations[0].ApiDetailUrl);
     // Stephen King was filtered out because he was created before the modified since date
 }
 public void Verify_Get_ByID_Should_ReturnTheCorrectLocation()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     // Act
     var locations = repository.Get(1);
     // Assert
                 Assert.Equal("/TEST/KING-STEPHEN", locations.ApiDetailUrl);
 }
Esempio n. 42
0
        public ActionResult Edit(int id = 0)
        {
            Inventory inventory;
            List<Inventory> relatedInventoryItemList;
            List<Location> locationsList;
            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                inventory = inventoryRep.GetEntity(id);

                if (inventory == null) return Error(Loc.Dic.error_inventory_item_not_found);

                locationsList = locationsRep.GetList().ToList();
                relatedInventoryItemList = inventoryRep.GetList("Orders_Items").ToList();
            }

            ViewBag.RelatedInventoryItem = new SelectList(relatedInventoryItemList, "Id", "Orders_Items.Title", inventory.RelatedInventoryItem);
            ViewBag.LocationId = new SelectList(locationsList, "Id", "Name", inventory.LocationId);
            return View(inventory);
        }
Esempio n. 43
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.InventoryManager))
                return Error(Loc.Dic.error_no_permission);

            IEnumerable<Location> locations;
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                locations = locationsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                locations = Pagination(locations, page, sortby, order);

                return View(locations.ToList());
            }
        }
 public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations, true);
     var repository = new LocationsRepository(mockContext.Object);
     var searchModel = new Mock<ILocationSearchModel>();
     // Act
     var locations = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray();
     // Assert
     Assert.Equal(1, locations.Length);
     Assert.Equal(2, locations[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", locations[0].MyApiDetailUrl);
     // Stephen King was filtered out because he was Inactive
 }
 public void Verify_Search_WithPaging_Should_ReturnAListOfLocationsWithDataMatchingSearchParameters()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var searchModel = new LocationSearchModel { Paging = new Paging { Skip = 1, Take = 1 } };
     // Act
     var locations = repository.Search(searchModel/*.Object*/).ToArray();
     // Assert
     Assert.Equal(1, locations.Length);
     Assert.Equal(2, locations[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", locations[0].ApiDetailUrl);
     // Stephen King was filtered out because he was Skipped
 }
 public void Verify_Update_Should_SetTheEntityStateToModified()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var locations = repository.Get(1);
     locations.ApiDetailUrl = "/TEST";
     // Act
     repository.Update(locations);
     // Assert
     mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once);
 }