public async Task <StoreProductCategory> UpdateAsync(string assignmentId, StoreProductCategory storeProductCat) { var existing = await GetAsync(assignmentId); existing.RankingValue = storeProductCat.RankingValue; await _context.SaveChangesAsync(); return(existing); }
private bool AssignmentExists(StoreProductCategory storeProductCat) { var assignments = _context.StoreProductCategories.ToList(); return(assignments.Any(a => a.StoreProductCategoryId == storeProductCat.StoreProductCategoryId || (a.ProductCategoryId == storeProductCat.ProductCategoryId && a.StoreId == storeProductCat.StoreId) )); }
public async Task <StoreProductCategory> CreateAsync(StoreProductCategory storeProductCat) { if (AssignmentExists(storeProductCat)) { throw new ItemAlreadyExistsException(typeof(StoreProductCategory), storeProductCat.StoreProductCategoryId); } _context.StoreProductCategories.Add(storeProductCat); await _context.SaveChangesAsync(); return(storeProductCat); }
public async Task <ActionResult <StoreProductCategoryResult> > CreateAssignment(StoreProductCategory assignment) { assignment.CreatedAt = DateTime.Now; StoreProductCategoryResult result = new StoreProductCategoryResult(); try { var created = await _storeProductCatRepository.CreateAsync(assignment); result.IsSuccessful = true; result.ResultData.Add(created); } catch (ItemAlreadyExistsException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(Conflict(result)); } catch (Exception e) { throw e; } return(Ok(result)); }
public async Task <ActionResult <StoreProductCategoryResult> > UpdateAssignment(string id, [FromBody] StoreProductCategory assignment) { StoreProductCategoryResult result = new StoreProductCategoryResult(); if (id != assignment.StoreProductCategoryId) { result.IsSuccessful = false; result.ErrorMessages.Add("Id does not match value in object"); return(BadRequest(result)); } try { var update = await _storeProductCatRepository.UpdateAsync(id, assignment); result.IsSuccessful = true; result.ResultData.Add(update); } catch (ItemNotFoundException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(NotFound(result)); } catch (ItemAlreadyExistsException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(NotFound(result)); } catch (Exception e) { throw e; } return(Ok(result)); }
/// <summary> /// Launches the Windows Store with the given category. /// </summary> /// <param name="category">The product category.</param> /// <returns>Returns True if successful, else False.</returns> public static async Task <bool> LaunchCategoryAsync(StoreProductCategory category) { var uriString = string.Format("ms-windows-store://browse/?type=Apps&cat={0}", category.GetDisplayValue()); return(await Windows.System.Launcher.LaunchUriAsync(new Uri(uriString))); }