Пример #1
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            WarehouseDto warehouse = (WarehouseDto)Session[_WarehouseDtoEditSessionKey];

            if (WarehouseId > 0 && warehouse == null)
            {
                warehouse = WarehouseManager.GetWarehouseByWarehouseId(WarehouseId);
            }
            else if (WarehouseId == 0)
            {
                warehouse = new WarehouseDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_WarehouseDtoString, warehouse);

            ViewControl.SaveChanges(context);

            if (warehouse.HasChanges())
            {
                WarehouseManager.SaveWarehouse(warehouse);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_WarehouseDtoEditSessionKey);
        }
Пример #2
0
        public void SaveChanges(IDictionary context)
        {
            WarehouseDto dto = (WarehouseDto)context[_WarehouseDtoString];

            WarehouseDto.WarehouseRow row = null;

            if (dto.Warehouse.Count > 0)
            {
                row          = dto.Warehouse[0];
                row.Modified = DateTime.UtcNow;
            }
            else
            {
                row           = dto.Warehouse.NewWarehouseRow();
                row.Created   = DateTime.UtcNow;
                row.Modified  = DateTime.UtcNow;
                row.CreatorId = Page.User.Identity.Name;
                row.IsPrimary = IsPrimary.IsSelected;
            }

            row.ModifierId    = Page.User.Identity.Name;
            row.Name          = Name.Text;
            row.Code          = CodeText.Text;
            row.IsActive      = this.IsActive.IsSelected;
            row.SortOrder     = Int32.Parse(this.SortOrder.Text);
            row.ApplicationId = CatalogConfiguration.Instance.ApplicationId;

            if (row.RowState == DataRowState.Detached)
            {
                dto.Warehouse.Rows.Add(row);
            }
        }
Пример #3
0
        public async Task <bool> AddWarehouseItemAsync([FromBody] WareHouseDepositRequest depositRequest)
        {
            var item = depositRequest.ItemInstance as IItemInstanceDto;

            item !.Id = Guid.NewGuid();
            item      = await _itemInstanceDao.TryInsertOrUpdateAsync(item).ConfigureAwait(true);

            var warehouse = new WarehouseDto
            {
                CharacterId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse ? null
                    : (long?)depositRequest.OwnerId,
                Id       = Guid.NewGuid(),
                FamilyId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse
                    ? (long?)depositRequest.OwnerId : null,
                Type = depositRequest.WarehouseType,
            };

            warehouse = await _warehouseDao.TryInsertOrUpdateAsync(warehouse).ConfigureAwait(true);

            var warehouseItem = new WarehouseItemDto
            {
                Slot           = depositRequest.Slot,
                Id             = Guid.NewGuid(),
                ItemInstanceId = item !.Id,
                WarehouseId    = warehouse.Id
            };
            await _warehouseItemDao.TryInsertOrUpdateAsync(warehouseItem).ConfigureAwait(true);

            return(true);
        }
    }
Пример #4
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        private void LoadContext()
        {
            if (WarehouseId > 0)
            {
                WarehouseDto warehouse = null;
                if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes")))                 // load fresh on initial load
                {
                    warehouse = LoadFresh();
                }
                else                 // load from session
                {
                    warehouse = (WarehouseDto)Session[_WarehouseDtoEditSessionKey];

                    if (warehouse == null)
                    {
                        warehouse = LoadFresh();
                    }
                }

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_WarehouseDtoString, warehouse);

                // Call tabs load context
                ViewControl.LoadContext(dic);

                _Warehouse = warehouse;
            }
        }
Пример #5
0
        public void GetUnassignedOrders_CorrectData_ReturnsOrderData()
        {
            WarehouseDto warehouse = new WarehouseDto
            {
                Address  = "somewhere",
                Name     = "Warehouse 43",
                Location = new PointDto {
                    Longitude = 24.24, Latitude = 49.49
                }
            };

            var warehouseId = warehouseService.AddWarehouseAsync(warehouse).Result;

            OrderDto order = new OrderDto
            {
                WarehouseId = warehouseId,
                State       = OrderStateDto.NotAssigned,
                Destination = new PointDto {
                    Longitude = 24.49, Latitude = 49.24
                },
                Sender = new CustomerDto {
                    FirstName = "Sender", LastName = "1", PhoneNumber = "testnumbers", Email = "testemail"
                },
                Receiver = new CustomerDto {
                    FirstName = "Receiver", LastName = "1", PhoneNumber = "testnumbers", Email = "testemail"
                }
            };

            var orderId = orderService.AddOrderAsync(order).Result;

            order = orderService.GetUnassignedOrders().FirstOrDefault(o => o.Id == orderId);

            Assert.IsNotNull(order);
        }
        public async Task Update(WarehouseDto warehouseDto)
        {
            using (var db = new CourierHelperDb(_connectionString))
            {
                if (warehouseDto.Location == null)
                {
                    throw new ArgumentException("Warehouse location is required!");
                }

                Warehouse warehouse = db.WarehousesRepo.Get(warehouseDto.Id);

                if (warehouse == null)
                {
                    throw new ArgumentOutOfRangeException("");                     //todo: make better exception
                }

                warehouse.Location.Coordinates = new Point(warehouseDto.Location.Longitude, warehouseDto.Location.Latitude);
                warehouse.Address = warehouseDto.Address;
                warehouse.Name    = warehouseDto.Name;

                db.WarehousesRepo.Update(warehouse);

                await db.SaveAsync();
            }
        }
Пример #7
0
        public ActionResult CreateWarehouse([FromBody] WarehouseDto dto)
        {
            List <Product> products    = _prodRepo.GetByExpression(x => true).Data;
            Warehouse      warehouseDb = new Warehouse()
            {
                Name                = dto.Name,
                Address             = dto.Address,
                Capacity            = dto.Capacity,
                FunctioningCapacity = dto.FunctioningCapacity,
                AvailableProducts   = new List <WarehouseProduct>()
            };
            var result          = _repo.Save(warehouseDb);
            var existedproducts = dto.ProductsIds
                                  .Select(x => products.FirstOrDefault(y => y.Id == x))
                                  .Where(x => x != null);

            foreach (var prod in existedproducts)
            {
                WarehouseProduct newProd = new WarehouseProduct()
                {
                    Warehouse = warehouseDb,
                    Product   = prod
                };
                _prodWarRepo.Save(newProd);
            }
            return(Ok(_repo.DataSet.Include(w => w.AvailableProducts).Where(x => x.Id == Guid.Parse(result.Message))));
        }
        public async Task <int> AddWarehouseAsync(WarehouseDto warehouseDto)
        {
            using (var db = new CourierHelperDb(_connectionString))
            {
                if (warehouseDto.Location == null)
                {
                    throw new ArgumentException("Warehouse location is required!");
                }

                ActivePoint location = new ActivePoint
                {
                    Coordinates = new Point(warehouseDto.Location.Longitude, warehouseDto.Location.Latitude)
                };

                Warehouse warehouse = new Warehouse
                {
                    Location = location,
                    Address  = warehouseDto.Address,
                    Name     = warehouseDto.Name
                };

                db.WarehousesRepo.Create(warehouse);
                await db.SaveAsync();

                return(warehouse.Id);
            }
        }
Пример #9
0
        public bool AddWarehouseItem([FromBody] WareHouseDepositRequest depositRequest)
        {
            var item = depositRequest.ItemInstance as IItemInstanceDto;

            item !.Id = Guid.NewGuid();
            _itemInstanceDao.InsertOrUpdate(ref item);
            var warehouse = new WarehouseDto
            {
                CharacterId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse ? null
                    : (long?)depositRequest.OwnerId,
                Id       = Guid.NewGuid(),
                FamilyId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse
                    ? (long?)depositRequest.OwnerId : null,
                Type = depositRequest.WarehouseType,
            };

            _warehouseDao.InsertOrUpdate(ref warehouse);
            var warehouseItem = new WarehouseItemDto
            {
                Slot           = depositRequest.Slot,
                Id             = Guid.NewGuid(),
                ItemInstanceId = item.Id,
                WarehouseId    = warehouse.Id
            };

            _warehouseItemDao.InsertOrUpdate(ref warehouseItem);
            return(true);
        }
Пример #10
0
        private int GetWarehouseId(string warehouse)
        {
            WarehouseDto warehouses = WarehouseManager.GetWarehouseDto();

            if (warehouses.Warehouse != null)
            {
                DataRow[] drws        = null;
                int       warehouseId = 0;
                if (Int32.TryParse(warehouse, out warehouseId))
                {
                    drws = warehouses.Warehouse.Select(String.Format("WarehouseId = '{0}'", warehouseId));
                    if (drws.Length > 0)
                    {
                        return(warehouseId);
                    }
                }
                else
                {
                    drws = warehouses.Warehouse.Select(String.Format("Name LIKE '{0}'", warehouse.Replace("'", "''")));
                    if (drws.Length > 0)
                    {
                        return(((WarehouseDto.WarehouseRow)drws[0]).WarehouseId);
                    }
                }
            }
            return(0);
        }
Пример #11
0
        /// <summary>
        /// Gets the warehouses.
        /// </summary>
        /// <returns></returns>
        public static WarehouseDto GetWarehouseDto()
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalog-warehouse", CatalogConfiguration.Instance.ApplicationId.ToString());

            WarehouseDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (WarehouseDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                DataCommand cmd = CatalogDataHelper.CreateDataCommand();
                cmd.CommandText = "ecf_Warehouse";
                cmd.Parameters  = new DataParameters();
                cmd.Parameters.Add(new DataParameter("ApplicationId", CatalogConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                cmd.DataSet      = new WarehouseDto();
                cmd.TableMapping = DataHelper.MapTables("Warehouse");

                DataResult results = DataService.LoadDataSet(cmd);

                dto = (WarehouseDto)results.DataSet;

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogSchemaTimeout);
            }

            return(dto);
        }
Пример #12
0
        public async Task <bool> DepositItemAsync(long ownerId, WarehouseType warehouseType, ItemInstanceDto?itemInstance, short slot)
        {
            var item = itemInstance as IItemInstanceDto;

            item !.Id = Guid.NewGuid();
            item      = await _itemInstanceDao.TryInsertOrUpdateAsync(item).ConfigureAwait(true);

            var warehouse = new WarehouseDto
            {
                CharacterId = warehouseType == WarehouseType.FamilyWareHouse ? null
                    : (long?)ownerId,
                Id       = Guid.NewGuid(),
                FamilyId = warehouseType == WarehouseType.FamilyWareHouse
                    ? (long?)ownerId : null,
                Type = warehouseType,
            };

            warehouse = await _warehouseDao.TryInsertOrUpdateAsync(warehouse).ConfigureAwait(true);

            var warehouseItem = new WarehouseItemDto
            {
                Slot           = slot,
                Id             = Guid.NewGuid(),
                ItemInstanceId = item !.Id,
                WarehouseId    = warehouse.Id
            };
            await _warehouseItemDao.TryInsertOrUpdateAsync(warehouseItem).ConfigureAwait(true);

            return(true);
        }
    }
Пример #13
0
        public void AddOrder_AllNewData_NewOrderIsExistsInDb()
        {
            WarehouseDto warehouse = new WarehouseDto
            {
                Address  = "somewhere",
                Name     = "Warehouse 42",
                Location = new PointDto {
                    Longitude = 23.42, Latitude = 42.23
                }
            };

            var warehouseId = warehouseService.AddWarehouseAsync(warehouse).Result;

            OrderDto order = new OrderDto
            {
                WarehouseId = warehouseId,
                Destination = new PointDto {
                    Longitude = 23.23, Latitude = 42.42
                },
                Sender = new CustomerDto {
                    FirstName = "Sender", LastName = "1", PhoneNumber = "testnumbers", Email = "testemail"
                },
                Receiver = new CustomerDto {
                    FirstName = "Receiver", LastName = "1", PhoneNumber = "testnumbers", Email = "testemail"
                }
            };

            var orderId = orderService.AddOrderAsync(order).Result;

            order = orderService.GetOrderById(orderId);

            Assert.IsNotNull(order);
        }
Пример #14
0
        /// <summary>
        /// Binds the lists.
        /// </summary>
        private void BindLists()
        {
            // bind shipment packages
            if (PackageList.Items.Count <= 1)
            {
                ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                if (shippingDto.Package != null)
                {
                    foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows)
                    {
                        PackageList.Items.Add(new ListItem(row.Name, row.PackageId.ToString()));
                    }
                }
                PackageList.DataBind();
            }

            // bind warehouses
            if (WarehouseList.Items.Count <= 1)
            {
                WarehouseDto dto = WarehouseManager.GetWarehouseDto();
                if (dto.Warehouse != null)
                {
                    foreach (WarehouseDto.WarehouseRow row in dto.Warehouse.Rows)
                    {
                        WarehouseList.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString()));
                    }
                }

                WarehouseList.DataBind();
            }

            // bind merchants
            if (MerchantList.Items.Count <= 1)
            {
                CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                if (merchants.Merchant != null)
                {
                    foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows)
                    {
                        MerchantList.Items.Add(new ListItem(row.Name, row.MerchantId.ToString()));
                    }
                }
                MerchantList.DataBind();
            }

            // bind tax categories
            if (TaxList.Items.Count <= 1)
            {
                CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                if (taxes.TaxCategory != null)
                {
                    foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows)
                    {
                        TaxList.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString()));
                    }
                }
                TaxList.DataBind();
            }
        }
Пример #15
0
        public async Task <IActionResult> Update([FromBody] WarehouseDto warehouse)
        {
            _logger.LogInformation($"Renaming warehouse: {warehouse.Id} to {warehouse.Name}");

            var result = await _warehouseService.RenameWarehouse(warehouse);

            return(Ok(result));
        }
Пример #16
0
        public async Task <IActionResult> AddWarehouse([FromBody] WarehouseDto newWarehouse)
        {
            _logger.LogInformation($"Adding new location, {newWarehouse.Name}");

            var result = await _warehouseService.AddWarehouse(newWarehouse);

            return(Ok(result));
        }
        public IActionResult CreateWareHouse(WarehouseDto warehouseDto)
        {
            var warehouse = _mapper.Map <Warehouse>(warehouseDto);

            _context.Warehouses.Add(warehouse);
            _context.SaveChanges();
            return(Ok(warehouse));
        }
Пример #18
0
        /// <summary>
        /// Loads the fresh.
        /// </summary>
        /// <returns></returns>
        private WarehouseDto LoadFresh()
        {
            WarehouseDto warehouse = WarehouseManager.GetWarehouseByWarehouseId(WarehouseId);

            // persist in session
            Session[_WarehouseDtoEditSessionKey] = warehouse;

            return(warehouse);
        }
Пример #19
0
        public async Task <WarehouseVM> RenameWarehouse(WarehouseDto warehouse)
        {
            var entity = await GetWarehouseEntity(warehouse.Id);

            entity.Name        = warehouse.Name;
            entity.Description = warehouse.Description;

            var result = await _cosmicWarehouseRepo.UpdateWarehouse(entity);

            return(GetWarehouseAsViewModel(result));
        }
Пример #20
0
        public Response <WarehouseDto> Post(WarehouseDto warehouseDto, SessionModel sessionModel)
        {
            Response <WarehouseDto> response = null;
            var responseClient = restClient.PostAsync <Response <WarehouseDto> >("Warehouse/", warehouseDto, sessionModel);

            if (responseClient.IsSuccess)
            {
                response = responseClient;
            }
            return(response);
        }
        public WarehouseDto GetById(int warehouseId)
        {
            using (var db = new CourierHelperDb(_connectionString))
            {
                Warehouse warehouse = db.WarehousesRepo.Get(warehouseId);

                WarehouseDto warehouseDto = Mapper.Map <WarehouseDto>(warehouse);

                return(warehouseDto);
            }
        }
Пример #22
0
        public JsonResult SaveRepository([CustomizeValidator] WarehouseDto m)
        {
            var q = new Repositorys()
            {
                Id      = m.Id,
                Name    = m.Name,
                Address = m.Address
            };

            return(Json <string>(_warehouseRepository.Add(q), "保存成功!"));
        }
Пример #23
0
        public Response <WarehouseDto> Put(WarehouseDto warehouseDto, SessionModel sessionModel)
        {
            Response <WarehouseDto> response = null;
            var urlClient      = string.Format("Warehouse/{0}", warehouseDto.WarehouseId);
            var responseClient = restClient.PutAsync <Response <WarehouseDto> >(urlClient, warehouseDto, sessionModel);

            if (responseClient.IsSuccess)
            {
                response = responseClient;
            }
            return(response);
        }
Пример #24
0
        public async Task <WarehouseVM> AddWarehouse(WarehouseDto newWarehouse)
        {
            var newEntity = new Warehouse()
            {
                Name        = newWarehouse.Name,
                Description = newWarehouse.Description,
                Active      = true
            };

            var result = await _cosmicWarehouseRepo.AddWarehouse(newEntity);

            return(GetWarehouseAsViewModel(result));
        }
Пример #25
0
        public async Task Products_Get_ReturnsCorrectWarehousesData()
        {
            var result = await _controller.Get(sku : 43264);

            var actual = Assert.IsType <OkObjectResult>(result);
            var output = Assert.IsType <GetProductResult>(actual.Value);

            var expectedECommerce     = new WarehouseDto(quantity: 12, locality: "SP", type: "ECOMMERCE");
            var expectedPhysicalStore = new WarehouseDto(quantity: 3, locality: "MOEMA", type: "PHYSICAL_STORE");

            Assert.Contains(expectedECommerce, output.Inventory.Warehouses);
            Assert.Contains(expectedPhysicalStore, output.Inventory.Warehouses);
        }
Пример #26
0
        internal static WarehouseDto ToDto(StockEntry stockEntity, string name)
        {
            WarehouseDto dto = new WarehouseDto()
            {
                Name        = name,
                Brand       = stockEntity.Product.Brand,
                Description = stockEntity.Product.Description,
                ProductType = stockEntity.ProductType,
                ProductId   = stockEntity.ProductId,
                Quantity    = stockEntity.Quantity
            };

            return(dto);
        }
Пример #27
0
        /// <summary>
        /// Loads the data and data bind.
        /// </summary>
        /// <param name="sortExpression">The sort expression.</param>
        private void LoadDataAndDataBind(string sortExpression)
        {
            WarehouseDto dto = WarehouseManager.GetWarehouseDto();

            if (dto.Warehouse != null)
            {
                DataView view = dto.Warehouse.DefaultView;
                view.Sort             = sortExpression;
                MyListView.DataSource = view;
            }

            MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("WarehouseId");
            MyListView.DataBind();
        }
Пример #28
0
        /// <summary>
        /// Saves changes in WarehouseDto.
        /// </summary>
        /// <param name="dto">The dto.</param>
        public static void SaveWarehouse(WarehouseDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("WarehouseDto can not be null"));
            }

            DataCommand cmd = CatalogDataHelper.CreateDataCommand();

            using (TransactionScope scope = new TransactionScope())
            {
                DataHelper.SaveDataSetSimple(CatalogContext.MetaDataContext, cmd, dto, "Warehouse");
                scope.Complete();
            }
        }
Пример #29
0
 public ActionResult Delete(int id, WarehouseDto warehouseDto)
 {
     try
     {
         var response = warehouseRepository.Delete(id, SessionUsuario);
         if (response.IsSuccess)
         {
             return(RedirectToAction("Index"));
         }
         return(View());
     }
     catch
     {
         return(View());
     }
 }
Пример #30
0
        public async Task <IActionResult> Post([FromBody] WarehouseDto value)
        {
            if (value == null)
            {
                return(BadRequest("Datos Invalidos"));
            }

            Warehouse warehouse = new Warehouse {
                WhsCode   = value.WhsCode,
                WhsName   = value.WhsName,
                Active    = value.Active,
                ActiveCRM = value.ActiveCRM
            };

            var result = _context.Warehouses.Add(warehouse);

            if (result.State != EntityState.Added)
            {
                string Errors = "";
                return(BadRequest(Errors));
            }

            try {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException) {
                return(BadRequest("A database command did not affect the expected number of rows. This usually indicates an optimistic concurrency violation; that is, a row has been changed in the database since it was queried."));
            }
            catch (DbUpdateException) {
                return(BadRequest("An error occurred sending updates to the database."));
            }
            //catch (DbEntityValidationException) {
            //    return BadRequest("The save was aborted because validation of entity property values failed.");
            //}
            catch (NotSupportedException) {
                return(BadRequest("An attempt was made to use unsupported behavior such as executing multiple asynchronous commands concurrently on the same context instance."));
            }
            catch (ObjectDisposedException) {
                return(BadRequest("The context or connection have been disposed."));
            }
            catch (InvalidOperationException) {
                return(BadRequest("Some error occurred attempting to process entities in the context either before or after sending commands to the database."));
            }

            return(Ok());
        }
Пример #31
0
 public void CreateWarehouse(WarehouseDto model)
 {
     var warehouse = new Warehouse(model.Name, model.DisplayName, model.Description, model.Length, model.Length, model.Height);
     _eventBus.Publish(new WarehouseCreatedEvent(warehouse));
 }