public AppProduct GetAppProductByProductID(string productID) { productID = productID.ToUpper(); return(AppProducts .Where(x => x.ProductID.ToUpper().Equals(productID)) .FirstOrDefault()); }
public AppProduct GetAppProductByStoreID(string storeID) { storeID = storeID.ToUpper(); return(AppProducts .Where(x => x.StoreID.ToUpper().Equals(storeID)) .FirstOrDefault()); }
public async override Task RefreshAppProducts() { AppProducts.Clear(); var listingInfo = await GetListingInformationAsync(); foreach (var product in listingInfo.ProductListings) { var license = GetLicense(product.Value.ProductId); AppProduct appProduct = new AppProduct(license.ProductId, license.ProductId, false); appProduct.Name = product.Value.Name; appProduct.Description = product.Value.Description; appProduct.CurrentFormattedPrice = product.Value.FormattedPrice; appProduct.BaseFormattedPrice = product.Value.FormattedBasePrice; appProduct.ExpiryDate = license.ExpirationDate.DateTime; appProduct.Purchased = license.IsActive; if (license.IsConsumable) { appProduct.ProductType = ProductKind.Consumable; } else { appProduct.ProductType = ProductKind.Durable; } AppProducts.Add(appProduct); } // Invoke the event InvokeAppProductsChanged(); }
public async Task <AppProducts> Insert(AppProducts appProducts) { await _unitOfWork.AppProductsRepository.Add(appProducts); await _unitOfWork.SaveChangesAsync(); return(appProducts); }
public async override Task RefreshAppProducts() { var kinds = GetProductKinds(); var appLicense = await Context.GetAppLicenseAsync(); var result = await Context.GetAssociatedStoreProductsAsync(kinds.Select(x => x.ToString())); AppProducts.Clear(); foreach (var item in result.Products) { Debug.WriteLine($"Key: {item.Key} | StoreID: {item.Value.StoreId} | ProductID: {item.Value.InAppOfferToken}"); // Cache the value var storeProduct = item.Value; // Create the App Product AppProduct appProduct = new AppProduct(storeProduct.InAppOfferToken, storeProduct.StoreId); appProduct.Name = storeProduct.Title; appProduct.Description = storeProduct.Description; appProduct.CurrentFormattedPrice = storeProduct.Price.FormattedPrice; appProduct.BaseFormattedPrice = storeProduct.Price.FormattedBasePrice; // Parse the Product Type if (Enum.TryParse <ProductKind>(storeProduct.ProductKind, out ProductKind parsedProductKind)) { appProduct.ProductType = parsedProductKind; } else { appProduct.ProductType = ProductKind.Unknown; } // Add License Info appProduct.Purchased = storeProduct.IsInUserCollection; foreach (var license in appLicense.AddOnLicenses) { Debug.WriteLine($"Licence Key: {license.Key} == Product Key: {item.Key}"); if (license.Key.Contains(item.Key)) { appProduct.Purchased = license.Value.IsActive; appProduct.ExpiryDate = license.Value.ExpirationDate.DateTime; Debug.WriteLine($"Licence Found - Purchased: {appProduct.Purchased} | Expiry Date: {appProduct.ExpiryDate}"); break; } } // Finally, add to the main list Debug.WriteLine(appProduct); AppProducts.Add(appProduct); } InvokeAppProductsChanged(); }
public void Update(AppProducts entity) { try { _context.AppProducts.Update(entity); } catch (Exception ex) { var msg = ex.InnerException.Message; throw; } }
public async Task <List <AppRecipesGetDto> > GetRecipesGetDtoByProductId(AppRecipesQueryFilter filter) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); var recipes = await GetAllRecipesByProductId(filter.AppproductsId); if (recipes != null) { if (filter.SearchText != "" && filter.SearchText != null) { recipes = recipes.Where(x => x.Description.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Formula.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower())).ToList(); } List <AppRecipesGetDto> recipesDto = _mapper.Map <List <AppRecipesGetDto> >(recipes); foreach (var item in recipesDto) { AppProducts appProductsFind = await _appProductsService.GetById((int)item.AppproductsId); if (appProductsFind != null) { AppProductsGetDto appProductsGetDto = _mapper.Map <AppProductsGetDto>(appProductsFind); item.AppProductsGetDto = appProductsGetDto; } AppVariables appVariablesFind = await _appVariablesService.GetById((int)item.AppVariableId); if (appVariablesFind != null) { AppVariablesGetDto appVariablesGetDto = _mapper.Map <AppVariablesGetDto>(appVariablesFind); item.AppVariablesGetDto = appVariablesGetDto; } if (item.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)item.AppIngredientsId); if (appIngredientsFind != null) { AppIngredientsGetDto appIngredientsGetDto = _mapper.Map <AppIngredientsGetDto>(appIngredientsFind); item.AppIngredientsGetDto = appIngredientsGetDto; } } } resultDto = recipesDto; } return(resultDto); }
public static IMyApps GetApp() { IMyApps app = null; switch (Factory.SelectedPackage) { case Packages.Product: app = new AppProducts(); break; default: app = null; break; } return(app); }
public ActionResult CreateProduct() { // Create the product to be added to the database AppProducts NewProduct = new AppProducts(); NewProduct.ProductName = Request.Form["ProductName"]; NewProduct.ProductCost = Int32.Parse(Request.Form["ProductCost"]); NewProduct.ProductPrice = Int32.Parse(Request.Form["ProductPrice"]); NewProduct.ProductStock = Int32.Parse(Request.Form["ProductStock"]); NewProduct.ProductActive = true; // Add the new product to the database _db.AppProducts.Add(NewProduct); // Save changes _db.SaveChanges(); // Reload the page return(RedirectToAction("ProductsMain", "Products")); }
public async Task <AppProducts> Update(AppProducts appProducts) { try { var appProductsFind = await GetById(appProducts.Id); if (appProductsFind == null) { throw new Exception("Producto No existe"); } _unitOfWork.AppProductsRepository.Update(appProducts); await _unitOfWork.SaveChangesAsync(); var productUpdated = await GetById(appProducts.Id); return(productUpdated); } catch (Exception ex) { var msg = ex.InnerException.Message; return(null); } }
public async Task <(AppProduct, PurchaseResults)> Purchase(string id) { var license = GetLicense(id); // If the product does not exist, exit with null if (license == null) { Debug.WriteLine("This product does not exist"); throw new ArgumentException($"A product by ProductID of {id} does not exist", nameof(AppProduct.ProductID)); //return (null, null); } // If the license is valid, but we don't have the product, create the product var product = GetAppProductByProductID(id); if (product == null) { product = new AppProduct(id, id, false); AppProducts.Add(product); } // If the license is already active, simply return the product if (license.IsActive) { Debug.WriteLine("User already owns this product"); return(product, null); } try { PurchaseResults purchaseResults; if (DebugHelpers.DebugMode) { Debug.WriteLine("Debug mode active, Simulating product purchase"); purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync(id); Debug.WriteLine("Finished Simulating"); } else { Debug.WriteLine("Requesting Product Purchase"); purchaseResults = await CurrentApp.RequestProductPurchaseAsync(id); Debug.WriteLine("User finished interacting with purchase screen"); } switch (purchaseResults.Status) { case ProductPurchaseStatus.AlreadyPurchased: Debug.WriteLine("User already owns this product"); MarkProductPurchased(product); break; case ProductPurchaseStatus.Succeeded: Debug.WriteLine("User now owns this product"); MarkProductPurchased(product); break; case ProductPurchaseStatus.NotPurchased: Debug.WriteLine("User chose to not purchase the product"); product.Purchased = false; if (DebugHelpers.DebugMode) { Debug.WriteLine("Simulating Purchase"); MarkProductPurchased(product); } break; case ProductPurchaseStatus.NotFulfilled: Debug.WriteLine("A previous purchase was not fulfilled"); MarkProductPurchased(product); break; default: Debug.WriteLine("An unknown response occurred. Please try again later"); break; } return(product, purchaseResults); } catch (Exception ex) { ExceptionHelpers.PrintOutException(ex, $"Product Purchase Error ({id})"); } return(product, null); }
public async Task <ApiResponse <AppProductsGetDto> > UpdateProducts(AppProductsUpdateDto appProductsUpdateDto) { AppProductsGetDto resultDto = new AppProductsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto); try { AppProducts appProductsFind = await GetById(appProductsUpdateDto.Id); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Codigo de producto no existe, verifique por favor"; response.Meta = metadata; response.Data = resultDto; return(response); } if (appProductsUpdateDto.ExternalCode == "") { metadata.IsValid = false; metadata.Message = "Codigo Externo no es valido"; response.Meta = metadata; response.Data = resultDto; return(response); } AppUnits appUnitsFind = await _appUnitsService.GetById((int)appProductsUpdateDto.AppUnitsId); if (appUnitsFind == null) { metadata.IsValid = false; metadata.Message = "Unidad venta del Producto No existe"; response.Meta = metadata; response.Data = resultDto; return(response); } appUnitsFind = await _appUnitsService.GetById((int)appProductsUpdateDto.ProductionUnitId); if (appUnitsFind == null) { metadata.IsValid = false; metadata.Message = "Unidad Produccion del Producto No existe"; response.Meta = metadata; response.Data = resultDto; return(response); } MtrTipoMoneda mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById((long)appProductsUpdateDto.PrymaryMtrMonedaId); if (mtrTipoMonedaFind == null) { metadata.IsValid = false; metadata.Message = "Moneda Primaria No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById((long)appProductsUpdateDto.SecundaryMtrMonedaId); if (mtrTipoMonedaFind == null) { metadata.IsValid = false; metadata.Message = "Moneda Secundaria No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } AppSubCategory appSubCategory = await _unitOfWork.AppSubCategoryRepository.GetById((int)appProductsUpdateDto.AppSubCategoryId); if (appSubCategory == null) { metadata.IsValid = false; metadata.Message = "Subcategoria No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } appProductsFind.ProductionUnitId = appProductsUpdateDto.ProductionUnitId; appProductsFind.AppUnitsId = appProductsUpdateDto.AppUnitsId; appProductsFind.AppSubCategoryId = appProductsUpdateDto.AppSubCategoryId; appProductsFind.PrymaryMtrMonedaId = appProductsUpdateDto.PrymaryMtrMonedaId; appProductsFind.SecundaryMtrMonedaId = appProductsUpdateDto.SecundaryMtrMonedaId; appProductsFind.UnitPrice = appProductsUpdateDto.UnitPrice; appProductsFind.Description1 = appProductsUpdateDto.Description1; appProductsFind.Description2 = appProductsUpdateDto.Description2; appProductsFind.ExternalCode = appProductsUpdateDto.ExternalCode; appProductsFind.UserUpdate = appProductsUpdateDto.UsuarioConectado; appProductsFind.UpdatedAt = DateTime.Now; AppProducts appProductsUpdated = await Update(appProductsFind); if (appProductsUpdated != null) { resultDto = _mapper.Map <AppProductsGetDto>(appProductsUpdated); AppUnits AppUnitsFind = await _appUnitsService.GetById((int)appProductsUpdated.AppUnitsId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.AppUnitsGetDto = appUnitsGetDto; } if (resultDto.UrlImage == "" || resultDto.UrlImage == null) { resultDto.Link = _paginationOptions.UrlGetFiles + "NoImage.png"; } else { resultDto.Link = _paginationOptions.UrlGetFiles + resultDto.UrlImage; } metadata.IsValid = true; metadata.Message = $"Producto: {resultDto.Code} Actualizado Satisfactoriamente!!"; } else { metadata.IsValid = false; metadata.Message = "Registro No actualizado"; } response.Meta = metadata; response.Data = resultDto; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }
public async Task <ApiResponse <bool> > DeleteProduct(AppProductsDeleteDto dto) { bool resultDto = false; Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <bool> response = new ApiResponse <bool>(resultDto); try { AppProducts product = await GetById(dto.Id); if (product == null) { metadata.IsValid = false; metadata.Message = "Producto No existe!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } var recipes = await _unitOfWork.AppRecipesRepository.GetRecipesByProductId(dto.Id); if (recipes != null || recipes.Count > 0) { metadata.IsValid = false; metadata.Message = "Producto existe en la formulacion!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } resultDto = await Delete(dto.Id); metadata.IsValid = true; metadata.Message = $"Producto Eliminado Satisfactoriamente!"; response.Meta = metadata; response.Data = resultDto; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }
public async Task <ApiResponse <AppProductsGetDto> > GetProduct(int id) { AppProductsGetDto resultDto = new AppProductsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto); try { AppProducts appProductsFind = await GetById(id); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Codigo de producto no existe, verifique por favor"; response.Meta = metadata; response.Data = resultDto; return(response); } resultDto = _mapper.Map <AppProductsGetDto>(appProductsFind); AppUnits AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.AppUnitsId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.AppUnitsGetDto = appUnitsGetDto; } AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.ProductionUnitId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.ProductionUnitGetDto = appUnitsGetDto; } MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.PrymaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); resultDto.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto; } MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.SecundaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); resultDto.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto; } AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)appProductsFind.AppSubCategoryId); if (AppSubCategoryFind != null) { AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind); resultDto.AppSubCategoryGetDto = appSubCategoryGetDto; } if (resultDto.UrlImage == "" || resultDto.UrlImage == null) { resultDto.Link = _paginationOptions.UrlGetFiles + "NoImage.png"; } else { resultDto.Link = _paginationOptions.UrlGetFiles + resultDto.UrlImage; } response.Meta = metadata; response.Data = resultDto; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }
public async Task Add(AppProducts entity) { await _context.AppProducts.AddAsync(entity); }
public async Task <ApiResponse <List <AppRecipesGetDto> > > UpdateAppRecipes(AppRecipesUpdateDto dto) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppRecipesGetDto> > response = new ApiResponse <List <AppRecipesGetDto> >(resultDto); try { var recipe = await GetById(dto.Id); if (recipe == null) { metadata.IsValid = false; metadata.Message = "Receta no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppProducts appProductsFind = await _appProductsService.GetById((int)dto.AppproductsId); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Producto no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppVariables appVariablesFind = await _appVariablesService.GetById((int)dto.AppVariableId); if (appVariablesFind == null) { metadata.IsValid = false; metadata.Message = "Variable no existe!!"; response.Data = null; response.Meta = metadata; return(response); } if (dto.Formula.Length > 0) { dto.AppIngredientsId = null; } recipe.Code = appVariablesFind.Code; recipe.Description = appVariablesFind.Description; recipe.Quantity = dto.Quantity; recipe.SumValue = dto.SumValue; recipe.OrderCalculate = dto.OrderCalculate; recipe.IncludeInSearch = dto.IncludeInSearch; recipe.AfectaCosto = dto.AfectaCosto; recipe.Secuencia = dto.Secuencia; recipe.AppIngredientsId = dto.AppIngredientsId; if (dto.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)dto.AppIngredientsId); if (appIngredientsFind == null) { metadata.IsValid = false; metadata.Message = "Ingrediente no existe!!"; response.Data = null; response.Meta = metadata; return(response); } else { if (dto.AfectaCosto == true) { recipe.TotalCost = appIngredientsFind.Cost * recipe.Quantity; } else { recipe.TotalCost = 0; } } } else { if (dto.Formula == "" || dto.Formula == null) { metadata.IsValid = false; metadata.Message = "Debe Indicar Una formula o seleccionar un ingrediente!!"; response.Data = null; response.Meta = metadata; return(response); } recipe.TotalCost = 0; recipe.Formula = dto.Formula; recipe.FormulaValue = ""; } var updated = await Update(recipe); await UpdateVariableSearchByProduct((int)dto.AppproductsId); var listRecipeCalculate = await CalulateRecipeByProduct((int)dto.AppproductsId); metadata.IsValid = true; metadata.Message = "Receta actualizada!"; response.Data = listRecipeCalculate; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }
public async Task <ApiResponse <List <AppRecipesGetDto> > > CreateAppRecipes(AppRecipesCreateDto dto) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppRecipesGetDto> > response = new ApiResponse <List <AppRecipesGetDto> >(resultDto); try { AppRecipes appRecipes = _mapper.Map <AppRecipes>(dto); //var recipeByProductVariable = await GetRecipesByProductIdVariableId((int)dto.AppproductsId, (int)dto.AppVariableId); //if (recipeByProductVariable != null) //{ // metadata.IsValid = false; // metadata.Message = "Variable ya existe en este producto!!"; // response.Data = null; // response.Meta = metadata; // return response; //} AppProducts appProductsFind = await _appProductsService.GetById((int)dto.AppproductsId); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Producto no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppVariables appVariablesFind = await _appVariablesService.GetById((int)dto.AppVariableId); if (appVariablesFind == null) { metadata.IsValid = false; metadata.Message = "Variable no existe!!"; response.Data = null; response.Meta = metadata; return(response); } appRecipes.Code = appVariablesFind.Code; appRecipes.Description = appVariablesFind.Description; appRecipes.Quantity = dto.Quantity; appRecipes.SumValue = dto.SumValue; appRecipes.OrderCalculate = dto.OrderCalculate; appRecipes.IncludeInSearch = dto.IncludeInSearch; appRecipes.AfectaCosto = dto.AfectaCosto; appRecipes.Secuencia = dto.Secuencia; if (dto.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)dto.AppIngredientsId); if (appIngredientsFind == null) { metadata.IsValid = false; metadata.Message = "Ingrediente no existe!!"; response.Data = null; response.Meta = metadata; return(response); } else { if (dto.AfectaCosto == true) { appRecipes.TotalCost = appIngredientsFind.Cost * appRecipes.Quantity; } else { appRecipes.TotalCost = 0; } } } else { if (dto.Formula == "" || dto.Formula == null) { metadata.IsValid = false; metadata.Message = "Debe Indicar Una formula o seleccionar un ingrediente!!"; response.Data = null; response.Meta = metadata; return(response); } appRecipes.TotalCost = 0; appRecipes.Formula = dto.Formula; appRecipes.FormulaValue = ""; } var inserted = await Insert(appRecipes); await UpdateVariableSearchByProduct((int)dto.AppproductsId); var listRecipeCalculate = await CalulateRecipeByProduct((int)dto.AppproductsId); response.Data = listRecipeCalculate; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }
public async Task Delete(int id) { AppProducts entity = await GetById(id); _context.AppProducts.Remove(entity); }