Example #1
0
 public async Task UpdateOption(Guid optionID, ProductOptionModel option)
 {
     using (var work = GetUnitOfWork())
     {
         var optionToUpdate = work.ProductOptions.Get(optionID);
         _mapper.MapFromModelToExistEntity(option, optionToUpdate);
         await work.Commit();
     }
 }
Example #2
0
 public async Task AddOption(Guid productID, ProductOptionModel option)
 {
     using (var work = GetUnitOfWork())
     {
         var optionEntity = _mapper.MapFromModelToEntity(option);
         work.ProductOptions.Add(optionEntity);
         work.Products.Get(productID).ProductOptions.Add(optionEntity);
         await work.Commit();
     }
 }
        public async Task <HttpResponseMessage> CreateOption(Guid productId, ProductOptionModel option)
        {
            // validate
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            await productOptionRepository.CreateAsync(productId, option);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Example #4
0
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     option = (ProductOptionModel)this.FindResource("opt");
     POS_Option();
     fly.DataContext    = _itemViewModel;
     flyout.DataContext = newoption;
     webHandler.POS_add_ProductOptionCompleted += async(x, y) =>
     {
         if (y.Result == 1)
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("New option added", "new option was succefully added",
                                                  MessageDialogStyle.Affirmative);
         }
         else
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("Something went wrong", "try again in a little bit",
                                                  MessageDialogStyle.Affirmative);
         }
     };
     webHandler.POS_update_ProductOptionCompleted += async(x, y) =>
     {
         if (y.Result == 1)
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("option changes saved", "",
                                                  MessageDialogStyle.Affirmative);
         }
         else
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("Something went wrong", "try again in a little bit",
                                                  MessageDialogStyle.Affirmative);
         }
     };
     webHandler.POS_delete_ProductOptionCompleted += async(x, y) =>
     {
         if (y.Result == 1)
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("Option removed", "The option was removed",
                                                  MessageDialogStyle.Affirmative);
         }
         else
         {
             var win = (MetroWindow)Application.Current.MainWindow;
             var res = await win.ShowMessageAsync("Something went wrong", "try again in a little bit",
                                                  MessageDialogStyle.Affirmative);
         }
     };
 }
        protected void ConfigTest()
        {
            _testProductOptionModel = new ProductOptionModel()
            {
                Id          = new Guid("8F2E0176-35EE-4F0A-AE55-83023DDDB1A3"),
                Name        = "TestName",
                Description = "TestDescription",
                ProductId   = new Guid("8F2E0176-35EE-4F0A-AE55-83023D2DB1A3"),
            };
            _testProductOptionModel0 = new ProductOptionModel()
            {
                Id          = new Guid("8F2E0175-35EE-4F0A-AE55-83023D2DB1A3"),
                Name        = "TestName0",
                Description = "TestDescription0",
                ProductId   = new Guid("8F2E0176-35EE-4F0A-AE55-83023D2DB1A3"),
            };

            _testProductOption = new ProductOption()
            {
                Id          = new Guid("8F2E0176-35EE-4F0A-AE55-83023DDDB1A3"),
                Name        = "TestName",
                Description = "TestDescription",
                ProductId   = new Guid("8F2E0176-35EE-4F0A-AE55-83023D2DB1A3"),
            };
            _testProductOption0 = new ProductOption()
            {
                Id          = new Guid("8F2E0175-35EE-4F0A-AE55-83023D2DB1A3"),
                Name        = "TestName0",
                Description = "TestDescription0",
                ProductId   = new Guid("8F2E0176-35EE-4F0A-AE55-83023D2DB1A3"),
            };

            _testProduct = new Product()
            {
                Id             = new Guid("8F2E0176-35EE-4F0A-AE55-83023D2DB1A3"),
                Name           = "TestName",
                Description    = "TestDescription",
                Price          = 1.01m,
                DeliveryPrice  = 2.02m,
                ProductOptions = new List <ProductOption>(),
            };

            _helper._mockProductTable.Add(_testProduct);
            _testService = new ProductOptionService(_helper._mockUnitOfwork.Object);
        }
Example #6
0
 private async void catagorytList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         selected = (ProductOptionModel)optionList.SelectedItem;
         if (selected != null)
         {
             del.IsEnabled = true;
         }
     }
     catch (Exception)
     {
         update.IsEnabled  = false;
         del.IsEnabled     = false;
         update.Foreground = Brushes.Gray;
         del.Foreground    = Brushes.Gray;
         var win = (MetroWindow)Application.Current.MainWindow;
         var res = await win.ShowMessageAsync("Something went wrong", "Try again in a little bit",
                                              MessageDialogStyle.AffirmativeAndNegative);
     }
 }
        public async Task <HttpResponseMessage> UpdateOption(Guid id, ProductOptionModel option)
        {
            // validate
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var current = await productOptionRepository.GetByIdAsync(id);

            if (current == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            current.Name        = option.Name;
            current.Description = option.Description;

            await productOptionRepository.UpdateAsync(current);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Example #8
0
        /// <summary>
        /// get product option
        /// </summary>
        /// <param name="optionId">option id</param>
        /// <returns>product option</returns>
        public async Task <IProductOption> GetByIdAsync(Guid id)
        {
            IProductOption result = null;

            using (var conn = new SqlConnection(connString))
            {
                await conn.OpenAsync();

                var cmd = new SqlCommand("SELECT Id,ProductId,Name,Description FROM productoption WHERE Id=@id", conn);
                cmd.Parameters.AddWithValue("@id", id);
                var reader = await cmd.ExecuteReaderAsync();

                if (await reader.ReadAsync())
                {
                    result = new ProductOptionModel(reader);
                }

                reader.Close();
                conn.Close();
            }

            return(result);
        }
 public async Task UpdateOption(Guid optionId, [FromBody] ProductOptionModel option)
 {
     await _productOptionservice.UpdateOption(optionId, option);
 }
 public async Task CreateOption(Guid productId, [FromBody] ProductOptionModel option)
 {
     await _productOptionservice.AddOption(productId, option);
 }