public static bool FlagProductExistInStore(IGenericRepository <Pricing> pricingRepository, RetailerAddProductDTO retailerProductDTO, int branchId) { var pricing = pricingRepository.Find(x => x.Store == retailerProductDTO.StoreId && x.Branch == branchId && x.Product == retailerProductDTO.ProductId).ToList(); if (pricing.Count > 0) { return(true); } return(false); }
public static Enums.UpdateStatus IncludeProduct(this IGenericRepository <Pricing> pricingRepository, RetailerAddProductDTO retailerProductDTO, int branchId, string user) { var status = Enums.UpdateStatus.Failure; try { if (!FlagProductExistInStore(pricingRepository, retailerProductDTO, branchId)) { Pricing priceProduct = new Pricing { Product = retailerProductDTO.ProductId, CallForPrice = false, CreatedUser = user, SpecialPrice = retailerProductDTO.NewSpecialPrice, SpecialPriceDescription = retailerProductDTO.NewSpecialPriceDescription, Price = retailerProductDTO.NewPrice, AdditionalTax = retailerProductDTO.NewAdditionalTax, SpecialPriceStartDateTimeUtc = retailerProductDTO.NewPriceStartTime, SpecialPriceEndDateTimeUtc = retailerProductDTO.NewPriceEndTime, OldPrice = 0, Store = retailerProductDTO.StoreId, Branch = branchId }; pricingRepository.Add(priceProduct); status = Enums.UpdateStatus.Success; } else { status = Enums.UpdateStatus.AlreadyExist; } } catch { status = Enums.UpdateStatus.Error; } return(status); }
public string IncludeProducts(RetailerAddProductDTO retailerProduct) { var currentUser = ClaimsPrincipal.Current.Identity.Name; Enums.UpdateStatus status = Enums.UpdateStatus.Failure; if (retailerProduct.BranchIdList == null || retailerProduct.BranchIdList.Count <= 0) { retailerProduct.BranchIdList = GetBranchIdListFromStore(retailerProduct.StoreId); } try { foreach (var branch in retailerProduct.BranchIdList) { //For now We beleive if one branch is updated and sucess it is fine. anyway last branch value persist. status = _unitOfWork.PricingRepository.IncludeProduct(retailerProduct, branch, currentUser); } _unitOfWork.Commit(); } catch { status = Enums.UpdateStatus.Error; } return(status.ToString()); }