Ejemplo n.º 1
0
        public IActionResult GetCart()
        {
            try
            {
                var currentUser = User.Identity.Name;
                if (currentUser != null)
                {
                    OperationResult operationResult_carts = _uow.Carts.GetMyCarts(currentUser);
                    if (operationResult_carts.IsSuccess)
                    {
                        List <Cart> carts = (List <Cart>)operationResult_carts.ReturnObject;

                        apiResponsive = new ApiResponsive()
                        {
                            ErrorContent = null,
                            IsSucces     = true,
                            ReturnObject = carts.Select(x => x.CartDTtoRES())
                        };

                        return(Ok(apiResponsive));
                    }
                }

                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                    ErrorMessage = _localizer["KullaniciBulunamadi"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
            catch (Exception ex)
            {
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 2
0
        public IActionResult GetProductDetail(int id)
        {
            if (id != 0)
            {
                errorModels = new List <ErrorModel>();
                OperationResult operationResult_products = _uow.Products.GetProductDetail(id);
                if (operationResult_products.IsSuccess)
                {
                    Product product = (Product)operationResult_products.ReturnObject;

                    ProductRES productRES = product.ProductDTtoRES();

                    apiResponsive = new ApiResponsive
                    {
                        IsSucces     = true,
                        ErrorContent = null,
                        ReturnObject = productRES
                    };

                    return(Ok(apiResponsive));
                }
                else
                {
                    ErrorModel errorModel2 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.UrunGetirilemedi.ToString(),
                        ErrorMessage = _localizer["UrunGetirilemedi"]
                    };

                    errorModels.Add(errorModel2);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }
            }

            ErrorModel errorModel3 = new ErrorModel()
            {
                ErrorCode    = MessageNumber.ParametrelerHatali.ToString(),
                ErrorMessage = _localizer["ParametrelerHatali"]
            };

            errorModels.Add(errorModel3);

            apiResponsive = new ApiResponsive()
            {
                IsSucces     = false,
                ReturnObject = null,
                ErrorContent = errorModels
            };

            return(BadRequest(apiResponsive));
        }
Ejemplo n.º 3
0
        public IActionResult GetAllProducts()
        {
            errorModels = new List <ErrorModel>();
            OperationResult operationResult_products = _uow.Products.GetAllProducts();

            if (operationResult_products.IsSuccess)
            {
                List <Product> products = (List <Product>)operationResult_products.ReturnObject;

                List <ProductRES> productRESs = products.Select(x => x.ProductDTtoRES()).ToList();

                apiResponsive = new ApiResponsive
                {
                    IsSucces     = true,
                    ErrorContent = null,
                    ReturnObject = productRESs
                };

                return(Ok(apiResponsive));
            }
            else
            {
                ErrorModel errorModel2 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.UrunGetirilemedi.ToString(),
                    ErrorMessage = _localizer["UrunGetirilemedi"]
                };

                errorModels.Add(errorModel2);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetUserOrdersAsync(int pageNumber, int pageSize)
        {
            errorModels = new List <ErrorModel>();

            if (pageNumber != 0 && pageSize != 0)
            {
                var currentUser = User.Identity.Name;
                if (currentUser != null)
                {
                    AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                    if (appUser != null)
                    {
                        OperationResult operationResult_orders = _uow.Orders.GetUserOrders(currentUser, pageNumber, pageSize);
                        if (operationResult_orders.IsSuccess)
                        {
                            List <Order>    orders    = (List <Order>)operationResult_orders.ReturnObject;
                            List <OrderRES> orderRESs = orders.Select(x => x.OrderDTtoRES()).ToList();

                            return(Ok(new ApiResponsive()
                            {
                                ErrorContent = null,
                                IsSucces = true,
                                ReturnObject = orderRESs
                            }));
                        }
                        else
                        {
                            ErrorModel errorModel = new ErrorModel()
                            {
                                ErrorCode    = MessageNumber.SiparislerGetirilemedi.ToString(),
                                ErrorMessage = _localizer["SiparislerGetirilemedi"]
                            };

                            errorModels.Add(errorModel);

                            apiResponsive = new ApiResponsive()
                            {
                                IsSucces     = false,
                                ReturnObject = null,
                                ErrorContent = errorModels
                            };

                            return(BadRequest(apiResponsive));
                        }
                    }
                }

                ErrorModel errorModel2 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                    ErrorMessage = _localizer["KullaniciBulunamadi"]
                };

                errorModels.Add(errorModel2);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
            else
            {
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.ParametrelerHatali.ToString(),
                    ErrorMessage = _localizer["ParametrelerHatali"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetUserOrdersCountAsync()
        {
            errorModels = new List <ErrorModel>();
            var currentUser = User.Identity.Name;

            if (currentUser != null)
            {
                AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                if (appUser != null)
                {
                    OperationResult operationResult_ordersCount = _uow.Orders.GetUserOrdersCount(appUser.UserName);
                    if (operationResult_ordersCount.IsSuccess)
                    {
                        apiResponsive = new ApiResponsive()
                        {
                            ErrorContent = null,
                            IsSucces     = true,
                            ReturnObject = operationResult_ordersCount.ReturnObject
                        };

                        return(Ok(apiResponsive));
                    }
                    else
                    {
                        ErrorModel errorModel3 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.SiparisSayisiGetirilemedi.ToString(),
                            ErrorMessage = _localizer["SiparisSayisiGetirilemedi"]
                        };

                        errorModels.Add(errorModel3);

                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }
                }
            }

            ErrorModel errorModel2 = new ErrorModel()
            {
                ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                ErrorMessage = _localizer["KullaniciBulunamadi"]
            };

            errorModels.Add(errorModel2);

            apiResponsive = new ApiResponsive()
            {
                IsSucces     = false,
                ReturnObject = null,
                ErrorContent = errorModels
            };

            return(BadRequest(apiResponsive));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Checkout([FromBody] CheckoutModel_req checkoutModel)
        {
            try
            {
                var currentUser = User.Identity.Name;
                if (currentUser == null)
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.GetHashCode().ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }

                AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                if (appUser != null)
                {
                    if (!ModelState.IsValid)
                    {
                        ErrorModel errorModel3 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.ParametrelerHatali.GetHashCode().ToString(),
                            ErrorMessage = _localizer["ParametrelerHatali"]
                        };

                        errorModels.Add(errorModel3);

                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }

                    if (checkoutModel.PaymentMethod == PaymentMethod.CreditCard)
                    {
                        if (checkoutModel.OldAddressId != 0)
                        {
                            OperationResult operationResult_address = _uow.UserAddress.GetUserAddress(checkoutModel.OldAddressId);
                            if (operationResult_address.IsSuccess && operationResult_address.ReturnObject != null)
                            {
                                Order order = new Order()
                                {
                                    UserId        = appUser.Id,
                                    OrderDate     = DateTime.Now,
                                    OrderStatus   = OrderStatus.NotApproved,
                                    UserAddressId = checkoutModel.OldAddressId,
                                    TotalPrice    = 0
                                };

                                OperationResult operationResult_addOrder = _uow.Orders.Add(order);
                                if (operationResult_addOrder.IsSuccess)
                                {
                                    OperationResult operationResult_carts = _uow.Carts.GetMyCarts(currentUser);
                                    if (operationResult_carts.IsSuccess)
                                    {
                                        List <Cart> myCart = (List <Cart>)operationResult_carts.ReturnObject;
                                        if (myCart.Count != 0)
                                        {
                                            Order order2 = (Order)operationResult_addOrder.ReturnObject;

                                            ThreedsInitialize payment = sendIyzico(appUser, myCart, checkoutModel, (UserAddress)operationResult_address.ReturnObject, order2.Id.ToString(), _accessor.HttpContext.Connection.RemoteIpAddress.ToString());
                                            if (payment.Status == "success")
                                            {
                                                apiResponsive = new ApiResponsive()
                                                {
                                                    ErrorContent = null,
                                                    IsSucces     = true,
                                                    ReturnObject = payment.HtmlContent
                                                };

                                                return(Ok(apiResponsive));
                                            }
                                            else
                                            {
                                                _uow.Orders.Delete(order2);

                                                ErrorModel errorModel3 = new ErrorModel()
                                                {
                                                    ErrorCode    = MessageNumber.OdemeBasarisiz.GetHashCode().ToString(),
                                                    ErrorMessage = _localizer["OdemeBasarisiz"]
                                                };

                                                errorModels.Add(errorModel3);

                                                ErrorModel errorModel = new ErrorModel()
                                                {
                                                    ErrorCode    = payment.ErrorCode,
                                                    ErrorMessage = payment.ErrorMessage
                                                };

                                                errorModels.Add(errorModel);

                                                apiResponsive = new ApiResponsive()
                                                {
                                                    IsSucces     = false,
                                                    ReturnObject = null,
                                                    ErrorContent = errorModels
                                                };

                                                return(Ok(apiResponsive));
                                            }
                                        }
                                        else
                                        {
                                            ErrorModel errorModel3 = new ErrorModel()
                                            {
                                                ErrorCode    = MessageNumber.SepetBulunamadi.ToString(),
                                                ErrorMessage = _localizer["SepetBulunamadi"]
                                            };

                                            errorModels.Add(errorModel3);

                                            apiResponsive = new ApiResponsive()
                                            {
                                                IsSucces     = false,
                                                ReturnObject = null,
                                                ErrorContent = errorModels
                                            };

                                            return(Ok(apiResponsive));
                                        }
                                    }
                                    else
                                    {
                                        ErrorModel errorModel3 = new ErrorModel()
                                        {
                                            ErrorCode    = MessageNumber.SepetGetirilemedi.ToString(),
                                            ErrorMessage = _localizer["SepetGetirilemedi"]
                                        };

                                        errorModels.Add(errorModel3);

                                        apiResponsive = new ApiResponsive()
                                        {
                                            IsSucces     = false,
                                            ReturnObject = null,
                                            ErrorContent = errorModels
                                        };

                                        return(Ok(apiResponsive));
                                    }
                                }
                                else
                                {
                                    ErrorModel errorModel3 = new ErrorModel()
                                    {
                                        ErrorCode    = MessageNumber.SiparisEklenemedi.ToString(),
                                        ErrorMessage = _localizer["SiparisEklenemedi"]
                                    };

                                    errorModels.Add(errorModel3);

                                    apiResponsive = new ApiResponsive()
                                    {
                                        IsSucces     = false,
                                        ReturnObject = null,
                                        ErrorContent = errorModels
                                    };

                                    return(Ok(apiResponsive));
                                }
                            }
                            else
                            {
                                ErrorModel errorModel3 = new ErrorModel()
                                {
                                    ErrorCode    = MessageNumber.AdresBulunamadi.GetHashCode().ToString(),
                                    ErrorMessage = _localizer["AdresBulunamadi"]
                                };

                                errorModels.Add(errorModel3);

                                apiResponsive = new ApiResponsive()
                                {
                                    IsSucces     = false,
                                    ReturnObject = null,
                                    ErrorContent = errorModels
                                };

                                return(Ok(apiResponsive));
                            }
                        }
                        else
                        {
                            UserAddress userAddress = new UserAddress()
                            {
                                UserId       = appUser.Id,
                                Adress       = checkoutModel.Address,
                                AdressTitle  = checkoutModel.AddressTitle,
                                City         = checkoutModel.City,
                                District     = checkoutModel.District,
                                Neighborhood = checkoutModel.Neighborhood,
                                Zip          = checkoutModel.Zip
                            };
                            OperationResult operationResult_addAddress = _uow.UserAddress.Add(userAddress);
                            if (operationResult_addAddress.IsSuccess)
                            {
                                UserAddress     userAddress2          = (UserAddress)operationResult_addAddress.ReturnObject;
                                OperationResult operationResult_carts = _uow.Carts.GetMyCarts(currentUser);
                                if (operationResult_carts.IsSuccess)
                                {
                                    List <Cart> myCart = (List <Cart>)operationResult_carts.ReturnObject;
                                    if (myCart.Count != 0)
                                    {
                                        Order order = new Order()
                                        {
                                            UserId        = appUser.Id,
                                            OrderDate     = DateTime.Now,
                                            OrderStatus   = OrderStatus.NotApproved,
                                            UserAddressId = userAddress2.Id,
                                            TotalPrice    = 0
                                        };
                                        OperationResult operationResult_addOrder = _uow.Orders.Add(order);
                                        if (operationResult_addOrder.IsSuccess)
                                        {
                                            Order             order2  = (Order)operationResult_addOrder.ReturnObject;
                                            ThreedsInitialize payment = sendIyzico(appUser, myCart, checkoutModel, userAddress, order2.Id.ToString(), _accessor.HttpContext.Connection.RemoteIpAddress.ToString());
                                            if (payment.Status == "success")
                                            {
                                                apiResponsive = new ApiResponsive()
                                                {
                                                    ErrorContent = null,
                                                    IsSucces     = true,
                                                    ReturnObject = payment.HtmlContent
                                                };

                                                return(Ok(apiResponsive));
                                            }
                                            else
                                            {
                                                _uow.Orders.Delete(order2);
                                                _uow.UserAddress.Delete(userAddress2);


                                                ErrorModel errorModel3 = new ErrorModel()
                                                {
                                                    ErrorCode    = MessageNumber.OdemeBasarisiz.GetHashCode().ToString(),
                                                    ErrorMessage = _localizer["OdemeBasarisiz"]
                                                };

                                                errorModels.Add(errorModel3);

                                                ErrorModel errorModel = new ErrorModel()
                                                {
                                                    ErrorCode    = payment.ErrorCode,
                                                    ErrorMessage = payment.ErrorMessage
                                                };

                                                errorModels.Add(errorModel);

                                                apiResponsive = new ApiResponsive()
                                                {
                                                    IsSucces     = false,
                                                    ReturnObject = null,
                                                    ErrorContent = errorModels
                                                };

                                                return(Ok(apiResponsive));
                                            }
                                        }
                                        else
                                        {
                                            _uow.UserAddress.Delete(userAddress2);

                                            ErrorModel errorModel3 = new ErrorModel()
                                            {
                                                ErrorCode    = MessageNumber.SiparisEklenemedi.GetHashCode().ToString(),
                                                ErrorMessage = _localizer["SiparisEklenemedi"]
                                            };

                                            errorModels.Add(errorModel3);

                                            apiResponsive = new ApiResponsive()
                                            {
                                                IsSucces     = false,
                                                ReturnObject = null,
                                                ErrorContent = errorModels
                                            };

                                            return(Ok(apiResponsive));
                                        }
                                    }
                                    else
                                    {
                                        _uow.UserAddress.Delete(userAddress2);

                                        ErrorModel errorModel3 = new ErrorModel()
                                        {
                                            ErrorCode    = MessageNumber.SepetinizBos.GetHashCode().ToString(),
                                            ErrorMessage = _localizer["SepetinizBos"]
                                        };

                                        errorModels.Add(errorModel3);

                                        apiResponsive = new ApiResponsive()
                                        {
                                            IsSucces     = false,
                                            ReturnObject = null,
                                            ErrorContent = errorModels
                                        };

                                        return(Ok(apiResponsive));
                                    }
                                }
                                else
                                {
                                    _uow.UserAddress.Delete(userAddress2);

                                    ErrorModel errorModel3 = new ErrorModel()
                                    {
                                        ErrorCode    = MessageNumber.SepetGetirilemedi.GetHashCode().ToString(),
                                        ErrorMessage = _localizer["SepetGetirilemedi"]
                                    };

                                    errorModels.Add(errorModel3);

                                    apiResponsive = new ApiResponsive()
                                    {
                                        IsSucces     = false,
                                        ReturnObject = null,
                                        ErrorContent = errorModels
                                    };



                                    return(Ok(apiResponsive));
                                }
                            }
                            else
                            {
                                ErrorModel errorModel3 = new ErrorModel()
                                {
                                    ErrorCode    = MessageNumber.AdresEklenemedi.GetHashCode().ToString(),
                                    ErrorMessage = _localizer["AdresEklenemedi"]
                                };

                                errorModels.Add(errorModel3);

                                apiResponsive = new ApiResponsive()
                                {
                                    IsSucces     = false,
                                    ReturnObject = null,
                                    ErrorContent = errorModels
                                };

                                return(Ok(apiResponsive));
                            }
                        }
                    }
                    else if (checkoutModel.PaymentMethod == PaymentMethod.PaymentAtTheDoor)
                    {
                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = true,
                            ErrorContent = null,
                            ReturnObject = null
                        };

                        return(Ok(apiResponsive));
                    }
                    else
                    {
                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = true,
                            ErrorContent = null,
                            ReturnObject = null
                        };

                        return(Ok(apiResponsive));
                    }
                }
                else
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.GetHashCode().ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in {nameof(CheckoutController)} : {ex}");
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> GetUserAddressesAsync()
        {
            try
            {
                var currentUser = User.Identity.Name;
                if (currentUser != null)
                {
                    AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                    if (appUser != null)
                    {
                        OperationResult operationResult_addresses = _uow.UserAddress.FindAll(x => x.UserId == appUser.Id);
                        if (operationResult_addresses.IsSuccess)
                        {
                            List <UserAddress>   userAddresses  = (List <UserAddress>)operationResult_addresses.ReturnObject;
                            List <UserAdressRES> userAdressRESs = userAddresses.Select(x => x.UserAdressDTtoRES()).ToList();

                            apiResponsive = new ApiResponsive()
                            {
                                IsSucces     = true,
                                ErrorContent = null,
                                ReturnObject = userAdressRESs
                            };

                            return(Ok(apiResponsive));
                        }



                        ErrorModel errorModel1 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.AdresGetirirkenHata.ToString(),
                            ErrorMessage = _localizer["AdresGetirirkenHata"]
                        };

                        errorModels.Add(errorModel1);

                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }
                }


                ErrorModel errorModel2 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                    ErrorMessage = _localizer["KullaniciBulunamadi"]
                };

                errorModels.Add(errorModel2);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in {nameof(GetUserAddressesAsync)} : {ex}");

                ErrorModel errorModel2 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel2);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> AddToCartAsync([FromBody] List <CartModel_req> carts)
        {
            try
            {
                var  currentUser = User.Identity.Name;
                Cart newCart     = null;
                if (currentUser != null)
                {
                    AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                    OperationResult carts_operationResult = _uow.Carts.GetMyCarts(currentUser);
                    if (carts_operationResult.IsSuccess)
                    {
                        List <Cart> cartsModel = (List <Cart>)carts_operationResult.ReturnObject;
                        List <Cart> addCarts   = new List <Cart>();


                        foreach (var cart in cartsModel)
                        {
                            for (int i = 0; i < carts.Count; i++)
                            {
                                if (carts[i].Id == cart.ProductAmountType.Id)
                                {
                                    cart.Quantity = cart.Quantity + carts[i].Quantity;
                                    carts.Remove(carts[i]);
                                }
                            }
                        }
                        _uow.SaveChanges();

                        foreach (var cart in carts)
                        {
                            OperationResult productAmountType_operationResult = _uow.ProductAmountTypes.Get(cart.Id);
                            if (productAmountType_operationResult.IsSuccess && productAmountType_operationResult.ReturnObject != null)
                            {
                                newCart = new Cart()
                                {
                                    AddToCartDate     = DateTime.Now,
                                    Quantity          = cart.Quantity,
                                    User              = appUser,
                                    ProductAmountType = (ProductAmountType)productAmountType_operationResult.ReturnObject,
                                };

                                addCarts.Add(newCart);
                            }
                            else
                            {
                                //hata
                            }
                        }

                        _uow.Carts.AddRange(addCarts);

                        apiResponsive = new ApiResponsive()
                        {
                            ErrorContent = null,
                            IsSucces     = true,
                            ReturnObject = null
                        };
                        return(Ok(apiResponsive));
                    }
                    else
                    {
                        ErrorModel errorModel3 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.SepetGetirilemedi.ToString(),
                            ErrorMessage = _localizer["SepetGetirilemedi"]
                        };

                        errorModels.Add(errorModel3);

                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }
                }
                else
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }
            }
            catch (Exception ex)
            {
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel3);

                _logger.LogError($"Error in {nameof(AddToCartAsync)} : {ex}");


                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> UpdateToCart([FromBody] List <CartModel_req> carts)
        {
            try
            {
                var currentUser = User.Identity.Name;
                if (currentUser == null)
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }

                AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                if (appUser != null)
                {
                    OperationResult operationResult_cartsModel = _uow.Carts.GetMyCarts(appUser.UserName);
                    if (operationResult_cartsModel.IsSuccess)
                    {
                        List <Cart> cartsModel = (List <Cart>)operationResult_cartsModel.ReturnObject;
                        foreach (var cart in carts)
                        {
                            foreach (var cartModel in cartsModel)
                            {
                                if (cart.Id == cartModel.Id)
                                {
                                    cartModel.Quantity = cart.Quantity;
                                }
                            }
                        }

                        _uow.SaveChanges();


                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = true,
                            ReturnObject = null,
                            ErrorContent = null
                        };

                        return(Ok(apiResponsive));
                    }
                    else
                    {
                        ErrorModel errorModel3 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.SepetGetirilemedi.ToString(),
                            ErrorMessage = _localizer["SepetGetirilemedi"]
                        };

                        errorModels.Add(errorModel3);

                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }
                }
                else
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);
                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }
            }
            catch
            {
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> DeleteToCart([FromBody] int cartId)
        {
            try
            {
                var currentUser = User.Identity.Name;
                if (currentUser == null)
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                        ErrorMessage = _localizer["KullaniciBulunamadi"]
                    };

                    errorModels.Add(errorModel3);

                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }

                if (cartId != 0)
                {
                    AppUser appUser = await _userManager.FindByNameAsync(currentUser);

                    if (appUser != null)
                    {
                        OperationResult operationResult_deleteCart = _uow.Carts.Find(x => x.Id == cartId & x.User.Id == appUser.Id);
                        if (operationResult_deleteCart.IsSuccess)
                        {
                            Cart cart = (Cart)operationResult_deleteCart.ReturnObject;
                            if (cart != null)
                            {
                                OperationResult operationResult_deletedCart = _uow.Carts.Delete(cart);
                                if (operationResult_deletedCart.IsSuccess)
                                {
                                    apiResponsive = new ApiResponsive()
                                    {
                                        IsSucces     = true,
                                        ErrorContent = null,
                                        ReturnObject = null
                                    };

                                    return(Ok(apiResponsive));
                                }
                                else
                                {
                                    ErrorModel errorModel3 = new ErrorModel()
                                    {
                                        ErrorCode    = MessageNumber.SepetSilinemedi.ToString(),
                                        ErrorMessage = _localizer["SepetSilinemedi"]
                                    };
                                    errorModels.Add(errorModel3);
                                    apiResponsive = new ApiResponsive()
                                    {
                                        IsSucces     = false,
                                        ReturnObject = null,
                                        ErrorContent = errorModels
                                    };

                                    return(Ok(apiResponsive));
                                }
                            }
                            else
                            {
                                ErrorModel errorModel3 = new ErrorModel()
                                {
                                    ErrorCode    = MessageNumber.SepetBulunamadi.ToString(),
                                    ErrorMessage = _localizer["SepetBulunamadi"]
                                };
                                errorModels.Add(errorModel3);
                                apiResponsive = new ApiResponsive()
                                {
                                    IsSucces     = false,
                                    ReturnObject = null,
                                    ErrorContent = errorModels
                                };

                                return(Ok(apiResponsive));
                            }
                        }
                        else
                        {
                            ErrorModel errorModel3 = new ErrorModel()
                            {
                                ErrorCode    = MessageNumber.SepetBulunamadi.ToString(),
                                ErrorMessage = _localizer["SepetBulunamadi"]
                            };
                            errorModels.Add(errorModel3);
                            apiResponsive = new ApiResponsive()
                            {
                                IsSucces     = false,
                                ReturnObject = null,
                                ErrorContent = errorModels
                            };

                            return(Ok(apiResponsive));
                        }
                    }
                    else
                    {
                        ErrorModel errorModel3 = new ErrorModel()
                        {
                            ErrorCode    = MessageNumber.KullaniciBulunamadi.ToString(),
                            ErrorMessage = _localizer["KullaniciBulunamadi"]
                        };

                        errorModels.Add(errorModel3);
                        apiResponsive = new ApiResponsive()
                        {
                            IsSucces     = false,
                            ReturnObject = null,
                            ErrorContent = errorModels
                        };

                        return(BadRequest(apiResponsive));
                    }
                }
                else
                {
                    ErrorModel errorModel3 = new ErrorModel()
                    {
                        ErrorCode    = MessageNumber.ParametrelerHatali.ToString(),
                        ErrorMessage = _localizer["ParametrelerHatali"]
                    };

                    errorModels.Add(errorModel3);
                    apiResponsive = new ApiResponsive()
                    {
                        IsSucces     = false,
                        ReturnObject = null,
                        ErrorContent = errorModels
                    };

                    return(BadRequest(apiResponsive));
                }
            }
            catch
            {
                ErrorModel errorModel3 = new ErrorModel()
                {
                    ErrorCode    = MessageNumber.BeklenmedikHata.ToString(),
                    ErrorMessage = _localizer["BeklenmedikHata"]
                };

                errorModels.Add(errorModel3);

                apiResponsive = new ApiResponsive()
                {
                    IsSucces     = false,
                    ReturnObject = null,
                    ErrorContent = errorModels
                };

                return(BadRequest(apiResponsive));
            }
        }