ResultModel IManagerOfProducts.UpdateProductStatus(Guid idOfProductToBeUpdate, bool newStatusValue) { int numberOfRowsAffected = default(int); ResultModel resultModel = default(ResultModel); if (idOfProductToBeUpdate == Guid.Empty) { return(ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.ProductIdCannotBeEmpty)); } try { DTOOfProducts getProductById = this.MapperOfProduct .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfProducts .FetchAnyRecord(id: idOfProductToBeUpdate)); if (getProductById == null) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.NoProductsFound); } else { getProductById.Status = newStatusValue; DTOOfProducts updatedProduct = this.MapperOfProduct .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfProducts .UpdateRecord(recordToUpdate: this.MapperOfProduct .MapToEntity(dtoObject: getProductById))); numberOfRowsAffected = this.UnitOfWorkForBasketApplication.SaveChanges(); if (numberOfRowsAffected > 0) { resultModel = ResultModel.SuccessfulResult(messageOfResultSuccessful: ConstantsOfResults.ProductUpdateSuccessful); } else { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.ProductUpdateUnsuccessful); } } } catch (Exception exception) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: $"{ConstantsOfErrors.TransactionErrorMessageOfUpdateProductStatus} HATA : {exception.Message}"); } finally { this.UnitOfWorkForBasketApplication.Dispose(); } return(resultModel); }
ResultModelOfSelectProduct IManagerOfProducts.FetchProductById(Guid idOfProduct) { ResultModel resultModel = default(ResultModel); WebAPIModelOfSelectProduct resultToReturnOfProductInformation = default(WebAPIModelOfSelectProduct); if (idOfProduct == Guid.Empty) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.ProductIdCannotBeEmpty); } else { try { DTOOfProducts getProductByIdAndStatus = this.MapperOfProduct .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfProducts .FetchAnyRecord(whereConditions: x => x.Status == true && x.Id == idOfProduct)); if (getProductByIdAndStatus == null) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.NoProductsFound); } else { resultToReturnOfProductInformation = new WebAPIModelOfSelectProduct { ProductId = getProductByIdAndStatus.Id, ProductName = getProductByIdAndStatus.Name, ProductPrice = getProductByIdAndStatus.Price }; resultModel = ResultModel.SuccessfulResult(messageOfResultSuccessful: ConstantsOfResults.ProductSearchIsSuccessful); } } catch (Exception exception) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: $"{ConstantsOfErrors.TransactionErrorMessageOfFetchProduct} HATA : {exception.Message}"); } } return(new ResultModelOfSelectProduct { InformationOfSuccess = resultModel, InformationOfProduct = resultToReturnOfProductInformation }); }
ResultModel IManagerOfMemberBaskets.BuyProductsInCart(Guid idOfBasketOwnerId) { ResultModel resultModel = default(ResultModel); var isThereAnyMember = this.ManagerOfMembers.FetchMemberById(idOfMember: idOfBasketOwnerId); if (!isThereAnyMember.SuccessInformation.IsResultSuccessful && isThereAnyMember.MemberInformation == null) { return(isThereAnyMember.SuccessInformation); } try { var allProductsOwnedByTheMember = this.FetchAllProductsOwnedByTheMember(idOfBasketOwner: idOfBasketOwnerId); if (!allProductsOwnedByTheMember.Any()) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.YouHaveNoItemsInYourCart); } else { int numberOfRowsAffected, numberOfProductsToBeUpdated = default(int); foreach (DTOOfMemberBaskets productInfoInTheBasket in allProductsOwnedByTheMember) { /* Satin alinmak istenilen URUN'e ait bilgiler listeleniyor. */ var fetchProductInfoByProductId = this.ManagerOfProducts .FetchProductById(idOfProduct: productInfoInTheBasket.ProductId); if (!fetchProductInfoByProductId.InformationOfSuccess.IsResultSuccessful && fetchProductInfoByProductId.InformationOfProduct == null) { return(fetchProductInfoByProductId.InformationOfSuccess); } /* Satin alinmak istenilen URUN'e ait STOK bilgisi listeleniyor */ var fetchProductStockInfoByProductId = this.ManagerOfProductStocks .FetchProductStockInformationByProductId(productId: fetchProductInfoByProductId.InformationOfProduct.ProductId); if (!fetchProductStockInfoByProductId.InformationOfSuccess.IsResultSuccessful && fetchProductStockInfoByProductId.InformationOfProductStock == null) { return(fetchProductStockInfoByProductId.InformationOfSuccess); } /* Satin alinmak istenilen URUN'e ait URUN adeti ile URUN'e ait STOK adeti karsilastirilmasi yapiliyor. * Alinmak istenilen URUN adeti, STOK adetine esit veya kucuk ise satis yapilir */ if (productInfoInTheBasket.Quantity <= fetchProductStockInfoByProductId.InformationOfProductStock.ProductStockQuantity) { #region KULLANICI'ya ait SEPET'teki tum URUN'lerin ClosingReasonType degeri Ordered (Satildi) olarak ayarlanir ve SEPET guncellenir productInfoInTheBasket.Status = false; productInfoInTheBasket.ReleaseDate = DateTime.Now; productInfoInTheBasket.ClosingReasonId = (byte)BasketClosingReasonTypes.Ordered; DTOOfMemberBaskets wasItUpdatedBasket = this.MapperOfMemberBaskets .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfMemberBaskets .UpdateRecord(recordToUpdate: this.MapperOfMemberBaskets .MapToEntity(dtoObject: productInfoInTheBasket))); #endregion KULLANICI'ya ait SEPET'teki tum URUN'lerin ClosingReasonType degeri Ordered (Satildi) olarak ayarlanir ve SEPET guncellenir #region Satin alinan URUN'ler icin satin alinan URUN adedi kadar STOK azaltimi yapilir fetchProductStockInfoByProductId.InformationOfProductStock.ProductStockQuantity -= productInfoInTheBasket.Quantity; DTOOfProductStocks wasItUpdatedProductStock = this.MapperOfProductStock .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfProductStocks .UpdateRecord(recordToUpdate: this.MapperOfProductStock .MapToEntity(dtoObject: new DTOOfProductStocks { Id = fetchProductStockInfoByProductId .InformationOfProductStock .ProductStockId, ProductId = fetchProductStockInfoByProductId .InformationOfProductStock .ProductId, Quantity = fetchProductStockInfoByProductId .InformationOfProductStock .ProductStockQuantity }))); #endregion Satin alinan URUN'ler icin satin alinan URUN adedi kadar STOK azaltimi yapilir #region URUN STOK degeri 0 veya daha az olursa URUN'un satilmamasi icin URUN'un Status degeri false yapilir if (wasItUpdatedProductStock.Quantity <= 0) { numberOfProductsToBeUpdated++; DTOOfProducts wasItUpdatedProduct = this.MapperOfProduct .MapToDTO(entityObject: this.UnitOfWorkForBasketApplication .RepositoryOfProducts .UpdateRecord(recordToUpdate: this.MapperOfProduct .MapToEntity(dtoObject: new DTOOfProducts { Status = false, Name = fetchProductInfoByProductId .InformationOfProduct .ProductName, Price = fetchProductInfoByProductId .InformationOfProduct .ProductPrice, Id = wasItUpdatedProductStock.ProductId }))); } #endregion URUN STOK degeri 0 veya daha az olursa URUN'un satilmamasi icin URUN'un Status degeri false yapilir } else { return(ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: $"Sepetinizde olan ve SATIN almak istediginiz " + $"{fetchProductInfoByProductId.InformationOfProduct.ProductName} adli URUN icin " + $"yeterli sayida STOK bulunmamaktadir. Lutfen almak istediginiz bu URUN icin adet " + $"sayisi en fazla {fetchProductStockInfoByProductId.InformationOfProductStock.ProductStockQuantity} " + $"tane olacak sekilde siparisinizi yeniden giriniz!")); } } numberOfRowsAffected = this.UnitOfWorkForBasketApplication.SaveChanges(); if (numberOfRowsAffected == ((allProductsOwnedByTheMember.Count() * 2) + numberOfProductsToBeUpdated)) { resultModel = ResultModel.SuccessfulResult(messageOfResultSuccessful: ConstantsOfResults.BuyProductsInBasketIsSuccessful); } else { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: ConstantsOfResults.BuyProductsInBasketIsUnsuccessful); } } } catch (Exception exception) { resultModel = ResultModel.UnsuccessfulResult(messageOfResultUnsuccessful: $"{ConstantsOfErrors.TransactionErrorMessageOfBuyProductsInBasket} HATA : {exception.Message}"); } finally { this.UnitOfWorkForBasketApplication.Dispose(); } return(resultModel); }