// GET http://localhost:8005/api/sync/inventorystocks/{reqDate}/{serialNo}
        // GET http://localhost:8005/api/sync/inventorystocks/2014-11-23/920013c000814
        public IHttpActionResult GetInventorystocks(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new InventoryStockSyncCollection();

            var allInventoryStocks = ProductServices.GetAllInventoryStocks(terminal.TenantId, terminal.WarehouseId, reqDate);

            var inventoryStocks = new List <InventoryStockSync>();

            foreach (var p in allInventoryStocks)
            {
                var inventory = new InventoryStockSync();
                var mapped    = AutoMapper.Mapper.Map(p, inventory);
                inventoryStocks.Add(mapped);
            }

            result.Count           = inventoryStocks.Count;
            result.TerminalLogId   = TerminalServices.CreateTerminalLog(reqDate, terminal.TenantId, inventoryStocks.Count, terminal.TerminalId, TerminalLogTypeEnum.InventoryStockSync).TerminalLogId;
            result.InventoryStocks = inventoryStocks;
            return(Ok(result));
        }
        // GET http://localhost:8005/api/sync/product-stock/{serialNo}/{productId}
        public IHttpActionResult GetInventoryStockForProduct(string serialNo, int productId, int warehouseId)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new InventoryStockSync();

            var inventoryStock = ProductServices.GetInventoryStocksByProductAndTenantLocation(productId, warehouseId);

            result = AutoMapper.Mapper.Map(inventoryStock, result);
            if (result != null)
            {
                result.LocationDetails = _commonDbServices.LocationsByProductDetails(productId, warehouseId);

                result.Count = result.LocationDetails.ProductDetails.Count;

                result.TerminalLogId = TerminalServices
                                       .CreateTerminalLog(DateTime.UtcNow, terminal.TenantId, 1, terminal.TerminalId,
                                                          TerminalLogTypeEnum.InventoryStockSync).TerminalLogId;

                return(Ok(result));
            }
            return(BadRequest("No stock information available for the requested product in the warehouse."));
        }
Exemple #3
0
        public ActionResult Create()
        {
            Db db = new Db(DbServices.ConnectionString);

            ViewBag.ProductList = new SelectList(ProductServices.List(db), "Id", "Notes");
            return(View());
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "Product, PaymentPeriod, Installment, NetAmount, ProfitAmount, SyrianPoundRounds")] RefundableProduct refundableProduct)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    RefundableProductServices.Insert(CurrentUser.Id, refundableProduct, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.ProductList = new SelectList(ProductServices.List(db), "Id", "Notes");
            return(View(refundableProduct));
        }
        public ActionResult Edit([Bind(Include = "Product, Date, Amount, Attachment, Cost, RequestStatus, BypassStatus, Notes")] Request request)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    RequestServices.Update(CurrentUser.Id, request, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.BypassStatusList  = new SelectList(BypassStatusServices.List(db), "Id", "Name", request.BypassStatus);
            ViewBag.ProductList       = new SelectList(ProductServices.List(db), "Id", "Notes", request.Product);
            ViewBag.RequestStatusList = new SelectList(RequestStatusServices.List(db), "Id", "Name", request.RequestStatus);
            return(View(request));
        }
        // GET http://localhost:8005/api/sync/productserials/{reqDate}/{serialNo}
        // GET http://localhost:8005/api/sync/productserials/2014-11-23/920013c000814
        public IHttpActionResult GetSerials(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new ProductSerialSyncCollection();

            var allSerials = ProductServices.GetAllProductSerialsByTenantId(terminal.TenantId, reqDate);

            var serials = new List <ProductSerialSync>();

            foreach (var p in allSerials)
            {
                var serial       = new ProductSerialSync();
                var mappedSerial = AutoMapper.Mapper.Map(p, serial);
                serials.Add(mappedSerial);
            }

            result.Count          = serials.Count;
            result.TerminalLogId  = TerminalServices.CreateTerminalLog(reqDate, terminal.TenantId, serials.Count, terminal.TerminalId, TerminalLogTypeEnum.ProductSerialSync).TerminalLogId;
            result.ProductSerials = serials;
            return(Ok(result));
        }
        public void Save(int userId, [FromBody] List <Product> products)
        {
            try
            {
                if (products.Count == 0)
                {
                    throw new RequestForbidden("Invalid Request");
                }
                UserProfile _user = AuthManager.CurrentUser;
                if (_user == null || userId != _user.Id)
                {
                    throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials);
                }

                ProductServices.Save(userId, products);
            }
            catch (RequestForbidden ex)
            {
                throw ExceptionResponse.Forbidden(Request, ex.Message);
            }
            catch (Exception ex)
            {
                throw ExceptionResponse.ServerErrorResponse(Request);
            }
        }
        public void TestAddProductShouldReturnNullReferenceException()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var genreServices  = new Mock <IGenreService>();
            var _searchService = new Mock <ISearchService>();
            var _userServices  = new Mock <IUserServices>();

            var productServices = new ProductServices(dbContext, genreServices.Object, _searchService.Object, _userServices.Object);
            //
            var title       = "Под игото";
            var testProduct = new Product()
            {
                Title        = "Бай Ганьо",
                ProductTypes = ProductTypes.Book,
                Price        = 153.03M,
                Quantity     = 1
            };

            productServices.AddProduct(testProduct);

            var testIsInDb = dbContext.Products.SingleOrDefault(x => x.Title == title);

            Assert.Null(testIsInDb);
        }
        public ActionResult EditProduct(int id)
        {
            var product = new Product();

            try
            {
                if (id < 1)
                {
                    product.Error     = "Invalid Selection!";
                    product.ErrorCode = -1;
                    return(Json(product, JsonRequestBehavior.AllowGet));
                }

                var myViewObj = new ProductServices().GetProduct(id);

                if (myViewObj == null || myViewObj.ProductId < 1)
                {
                    product.Error     = "Product Information could not be retrieved.";
                    product.ErrorCode = -1;
                    return(Json(product, JsonRequestBehavior.AllowGet));
                }
                Session["_product"] = myViewObj;
                myViewObj.ErrorCode = myViewObj.ProductId;
                return(Json(myViewObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                product.Error     = "An unknown error was Product Information could not be retrieved.";
                product.ErrorCode = -1;
                return(Json(product, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <IActionResult> Index(decimal?minAmount, decimal?maxAmount)
        {
            if (minAmount == null || maxAmount == null)
            {
                var products = await _db.Products.Include(m => m.ProductTypes)
                               .Include(m => m.SpecialTags)
                               .ToListAsync();

                return(View(products));
            }

            //var filterdProducts = await _db.Products.Where(m => m.Price >= minAmount && m.Price <= maxAmount)
            //                                    .Include(m=>m.ProductTypes)
            //                                    .Include(m=>m.SpecialTags)
            //                                    .ToListAsync();

            var productsList = await _db.Products.Include(m => m.ProductTypes)
                               .Include(m => m.SpecialTags)
                               .ToListAsync();

            ProductServices _productServices = new ProductServices();

            var filterdProducts = _productServices.FilterByMinMaxAmount(minAmount, maxAmount, productsList);


            return(View(filterdProducts));
        }
Exemple #11
0
        public ActionResult DeleteProduct(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                var delStatus = new ProductServices().DeleteProduct(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Product  could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "Product  Information was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        // GET: api/HandheldUserSync
        // call example through URI http://localhost:8005/api/GetProducts?ReqDate=2014-11-23&SerialNo=920013c000814
        public IHttpActionResult GetProducts(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new ProductMasterSyncCollection();

            var allProducts = ProductServices.GetAllValidProductMasters(terminal.TenantId, reqDate, true);
            var products    = new List <ProductMasterSync>();

            foreach (var p in allProducts)
            {
                var product       = new ProductMasterSync();
                var mappedProduct = AutoMapper.Mapper.Map(p, product);
                mappedProduct.ProductGroupName = p.Name;
                mappedProduct.DepartmentName   = p.TenantDepartment.DepartmentName;
                mappedProduct.TaxPercent       = p.GlobalTax.PercentageOfAmount;
                products.Add(mappedProduct);
            }

            result.Count         = products.Count;
            result.TerminalLogId = TerminalServices.CreateTerminalLog(reqDate, terminal.TenantId, products.Count(), terminal.TerminalId, TerminalLogTypeEnum.ProductsSync).TerminalLogId;
            result.Products      = products;
            return(Ok(result));
        }
Exemple #13
0
        public ProductServicesTest()
        {
            productService = new ProductServices(this.TContext);

            projectService  = new ProjectServices(this.TContext);
            businessService = new BusinessServices(this.TContext);
            quoteService    = new QuoteServices(this.TContext);

            user = GetUserSessionModel("*****@*****.**");

            _projectId = this.db.Context.Projects
                         .Where(p => p.OwnerId == user.UserId)
                         .OrderByDescending(p => p.ProjectId)
                         .Select(p => p.ProjectId)
                         .FirstOrDefault();

            projectModel = projectService.GetProjectModel(user, _projectId).Model as ProjectModel;

            _quoteId = this.db.Context.Quotes.Where(q => q.ProjectId == _projectId)
                       .OrderByDescending(q => q.QuoteId)
                       .Select(q => q.QuoteId)
                       .FirstOrDefault();

            _productNumber = this.db.Context.Products
                             .Select(pr => pr.ProductNumber)
                             .Where(pr => pr != null)
                             .FirstOrDefault();

            _quoteItemId = this.db.Context.QuoteItems
                           .Where(qi => qi.Quantity > 0)
                           .Select(qi => qi.QuoteItemId)
                           .FirstOrDefault();
        }
Exemple #14
0
        public void ThatAProductCanBeDeleted()
        {
            var product = GetProduct();

            ProductServices.Delete(product);
            Assert.IsNull(ProductServices.Products.SingleOrDefault(x => x.Name == product.Name));
        }
Exemple #15
0
        public void ScenarioA()
        {
            ProductServices products = new ProductServices(new MockAcceptValues());

            products.ProductCheckOut();
            //Assert.AreEqual();
        }
        public void ProductExistsReturnIsProductExistInDB()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var genreServices  = new Mock <IGenreService>();
            var _searchService = new Mock <ISearchService>();
            var _userServices  = new Mock <IUserServices>();

            var productServices = new ProductServices(dbContext, genreServices.Object, _searchService.Object, _userServices.Object);
            //
            var testProduct1 = new Product()
            {
                Id           = 1,
                Title        = "Бай Ганьо1",
                ProductTypes = ProductTypes.Book,
                Price        = 153.03M,
                Quantity     = 1
            };


            dbContext.Products.AddRange(testProduct1);
            dbContext.SaveChanges();


            var productFromDB = productServices.ProductExists(1);

            Assert.True(productFromDB);
        }
        public void TestGetProductByIdShouldReturnProduct()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var genreServices  = new Mock <IGenreService>();
            var _searchService = new Mock <ISearchService>();
            var _userServices  = new Mock <IUserServices>();

            var productServices = new ProductServices(dbContext, genreServices.Object, _searchService.Object, _userServices.Object);
            //
            var testProduct = new Product()
            {
                Id           = 1,
                Title        = "Бай Ганьо",
                ProductTypes = ProductTypes.Book,
                Price        = 153.03M,
                Quantity     = 1
            };

            productServices.AddProduct(testProduct);

            var productFromDB = productServices.GetProductById(1).Id == 1;


            Assert.True(productFromDB);
        }
Exemple #18
0
        public HttpResponseMessage UpdateProduct(int productID, Product product)
        {
            var updatedProduct = ProductServices.UpdateProduct(productID, product);

            var response = Request.CreateResponse(HttpStatusCode.OK, updatedProduct, Configuration.Formatters.JsonFormatter);

            response.Headers.Add("API-Version", apiVersion);
            response.Headers.Add("Response-Type", "JSON");
            response.Headers.Add("Updated-Product-URL", Request.RequestUri.AbsoluteUri);

            if (updatedProduct == null)
            {
                var notFoundResponse = Request.CreateResponse(HttpStatusCode.NotFound,
                                                              "(404) Product Not Found",
                                                              Configuration.Formatters.JsonFormatter);

                notFoundResponse.Headers.Add("API-Version", apiVersion);

                return(notFoundResponse);
            }
            else
            {
                return(response);
            }
        }
Exemple #19
0
        public HttpResponseMessage PostProduct(Product product)
        {
            var createdProduct = ProductServices.CreateProduct(product);

            // If product already exists within database, return 409.
            if (createdProduct == null)
            {
                var alreadyExistsResponse = Request.CreateResponse
                                                (HttpStatusCode.Conflict, "(409) Product already exists", Configuration.Formatters.JsonFormatter);

                alreadyExistsResponse.Headers.Add("API-Version", apiVersion);
                alreadyExistsResponse.Headers.Add("ERROR", "(409) Resource already exists");

                return(alreadyExistsResponse);
            }
            // Product doesn't exist inside the database, proceed.
            else
            {
                var response = Request.CreateResponse(HttpStatusCode.Created, product, Configuration.Formatters.JsonFormatter);
                response.Headers.Add("API-Version", apiVersion);
                response.Headers.Add("HTTP-Method", "POST");

                if (Request.RequestUri.AbsoluteUri.EndsWith("/"))
                {
                    response.Headers.Add("New-Product-URL", Request.RequestUri.AbsoluteUri + createdProduct.ID);
                }
                else
                {
                    response.Headers.Add("New-Product-URL", Request.RequestUri.AbsoluteUri + "/" + createdProduct.ID);
                }
                return(response);
            }
        }
Exemple #20
0
        // call example through URI http://localhost:8005/api/sync/get-pallet-tracking?ReqDate=2014-11-23&SerialNo=920013c000814
        public IHttpActionResult GetPallettracking(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new PalletTrackingSyncCollection();

            var allPallets = ProductServices.GetAllPalletTrackings(terminal.TenantId, terminal.WarehouseId, reqDate).ToList();
            var pallets    = new List <PalletTrackingSync>();

            foreach (var p in allPallets)
            {
                var pallet       = new PalletTrackingSync();
                var mappedPallet = AutoMapper.Mapper.Map(p, pallet);
                pallets.Add(mappedPallet);
            }

            result.Count              = pallets.Count;
            result.TerminalLogId      = TerminalServices.CreateTerminalLog(reqDate, terminal.TenantId, pallets.Count(), terminal.TerminalId, TerminalLogTypeEnum.PalletTrackingSync).TerminalLogId;
            result.PalletTrackingSync = pallets;
            return(Ok(result));
        }
 public ProductDetailsController()
 {
     unitOfWork            = new UnitOfWork();
     productDetailsService = new ProductDetailsServices(unitOfWork);
     itemServices          = new ItemServices(unitOfWork);
     productServices       = new ProductServices(unitOfWork);
 }
Exemple #22
0
        public ActionResult Edit([Bind(Include = "Id, Employee, ProductType, Amount, Notes")] Product product)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    ProductServices.Update(CurrentUser.Id, product, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.EmployeeList    = new SelectList(EmployeeServices.List(db), "Id", "FirstName", product.Employee);
            ViewBag.ProductTypeList = new SelectList(ProductTypeServices.List(db), "Id", "Name", product.ProductType);
            return(View(product));
        }
Exemple #23
0
 public DamagedProductController()
 {
     unitOfWork          = new UnitOfWork();
     damagedItemServices = new DamagedItemServices(unitOfWork);
     storeServices       = new StoreServices(unitOfWork);
     productServices     = new ProductServices(unitOfWork);
 }
Exemple #24
0
 public ProductControllerTest()
 {
     productService = new ProductServices(this.TContext);
     accountService = new AccountServices();
     user           = accountService.GetUserSessionModel("*****@*****.**").Model as UserSessionModel;
     routeData      = new RouteData();
 }
Exemple #25
0
        public IHttpActionResult Get()
        {
            ProductServices productService = CreateProductService();
            var             services       = productService.GetProducts();

            return(Ok(services));
        }
Exemple #26
0
        public ActionResult Detail(int id)
        {
            productRepository pr = new productRepository(new SSMEntities());

            try
            {
                softwareProduct product = pr.getById(id);
                if (product != null)
                {
                    List <double>   totalvalues = new List <double>();
                    ProductServices ps          = new ProductServices();
                    for (int i = 0; i < 12; i++)
                    {
                        totalvalues.Add(ps.getMonthValues(i, product.id));
                        System.Diagnostics.Debug.WriteLine("added " + ps.getMonthValues(i, product.id));
                    }
                    ViewData["productDetail"] = product;

                    ViewData["productperformance"] = totalvalues;
                    return(View("ProductDescription"));
                }
            }
            catch (Exception e)
            {
            }
            return(RedirectToAction("Index"));
        }
Exemple #27
0
        private ProductServices CreateProductService()
        {
            var userId         = Guid.Parse(User.Identity.GetUserId());
            var productService = new ProductServices(userId);

            return(productService);
        }
Exemple #28
0
        public async Task Delete_InvalidProduct_ReturnError(int id)
        {
            // ===== Arrange =====
            var dbName  = Guid.NewGuid().ToString();
            var context = BuildContext(dbName);
            var mapper  = BuildMap();

            var httpContext = new Mock <IHttpContextAccessor>();
            var http        = new DefaultHttpContext();

            httpContext.Setup(_ => _.HttpContext).Returns(http);

            await Generate_Product_Data(context, mapper, httpContext.Object);

            var data = await context.Product.Where(_ => _.Id == id).FirstOrDefaultAsync();

            // ===== Act ======
            var actContext = BuildContext(dbName);

            var service = new ProductServices(actContext, mapper, httpContext.Object);
            var result  = await service.Delete(id);

            // ===== Assert =====
            // Expected Exception
        }
Exemple #29
0
        public async Task Get_ValidProduct_ReturnDataWithSameID(int id)
        {
            // ===== Arrange =====
            var dbName      = Guid.NewGuid().ToString();
            var context     = BuildContext(dbName);
            var mapper      = BuildMap();
            var httpContext = new Mock <IHttpContextAccessor>();
            var http        = new DefaultHttpContext();

            httpContext.Setup(_ => _.HttpContext).Returns(http);

            await Generate_Product_Data(context, mapper, httpContext.Object);

            // ===== Act ======
            var accContext = BuildContext(dbName);

            var service = new ProductServices(accContext, mapper, httpContext.Object);
            var result  = await service.Get(id);

            // ===== Assert =====
            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(id, result.Data.Id);

            switch (id)
            {
            case 10:
                Assert.AreEqual("Test Product 1 Group D", result.Data.Name);
                break;

            case 15:
                Assert.AreEqual("Test Product 3 Group E", result.Data.Name);
                break;
            }
        }
Exemple #30
0
        public async Task GetAll_WithOrder_ReturnOrderedData()
        {
            // ===== Arrange =====
            var dbName      = Guid.NewGuid().ToString();
            var context     = BuildContext(dbName);
            var mapper      = BuildMap();
            var httpContext = new Mock <IHttpContextAccessor>();
            var http        = new DefaultHttpContext();

            httpContext.Setup(_ => _.HttpContext).Returns(http);

            await Generate_Product_Data(context, mapper, httpContext.Object);

            // ===== Act ======
            var accContext = BuildContext(dbName);

            var service = new ProductServices(accContext, mapper, httpContext.Object);
            var result  = await service.GetAll(new PaginationDto { }, new ProductFilterDTO(), new DataOrderDTO { OrderBy = "Name", Sort = "asd" });

            // ===== Assert =====
            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(result.TotalAmountRecords, 15);
            Assert.AreEqual(result.Data[0].Name, "Test Product 1 Group A");
            Assert.AreEqual(result.Data[1].Name, "Test Product 1 Group B");
        }
Exemple #31
0
 static void Main(string[] args)
 {
     var service = new ProductServices();
     service.Add()
 }