public override int GetHashCode()
        {
            int hash = 1;

            if (detailsCase_ == DetailsOneofCase.DeleteDetails)
            {
                hash ^= DeleteDetails.GetHashCode();
            }
            if (detailsCase_ == DetailsOneofCase.CreateModelDetails)
            {
                hash ^= CreateModelDetails.GetHashCode();
            }
            if (ProgressPercent != 0)
            {
                hash ^= ProgressPercent.GetHashCode();
            }
            hash ^= partialFailures_.GetHashCode();
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (updateTime_ != null)
            {
                hash ^= UpdateTime.GetHashCode();
            }
            hash ^= (int)detailsCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public void MergeFrom(OperationMetadata other)
        {
            if (other == null)
            {
                return;
            }
            if (other.ProgressPercent != 0)
            {
                ProgressPercent = other.ProgressPercent;
            }
            partialFailures_.Add(other.partialFailures_);
            if (other.createTime_ != null)
            {
                if (createTime_ == null)
                {
                    CreateTime = new global::Google.Protobuf.WellKnownTypes.Timestamp();
                }
                CreateTime.MergeFrom(other.CreateTime);
            }
            if (other.updateTime_ != null)
            {
                if (updateTime_ == null)
                {
                    UpdateTime = new global::Google.Protobuf.WellKnownTypes.Timestamp();
                }
                UpdateTime.MergeFrom(other.UpdateTime);
            }
            switch (other.DetailsCase)
            {
            case DetailsOneofCase.DeleteDetails:
                if (DeleteDetails == null)
                {
                    DeleteDetails = new global::Google.Cloud.AutoML.V1.DeleteOperationMetadata();
                }
                DeleteDetails.MergeFrom(other.DeleteDetails);
                break;

            case DetailsOneofCase.CreateModelDetails:
                if (CreateModelDetails == null)
                {
                    CreateModelDetails = new global::Google.Cloud.AutoML.V1.CreateModelOperationMetadata();
                }
                CreateModelDetails.MergeFrom(other.CreateModelDetails);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Beispiel #3
0
        public async Task <ResponseObject> Delete([FromBody] DeleteDetails dd)
        {
            Item     item     = new Item();
            Cart     cart     = new Cart();
            CartItem cartItem = new CartItem();

            response.SetContent(false, "Invalid inputs");
            if (dd.itemID == 0 && dd.cartID == 0)
            {
                return(response);
            }

            await HttpContext.Session.LoadAsync();

            var userId = HttpContext.Session.GetInt32("UserID") ?? 0;

            dd.cartID = HttpContext.Session.GetInt32("CartID") ?? dd.cartID;

            try
            {
                if (userId == 0)//***********Annonymous User
                {
                    await HttpContext.Session.LoadAsync();

                    cart = HttpContext.Session.GetObject <Cart>("AnnonymousCart") ?? await NewAnnonymousCart();

                    if (!cart.CartItems.Any <CartItem>(i => i.ItemId == dd.itemID))
                    {
                        response.SetContent(false, "Item not found in cart");
                    }
                    else
                    {
                        //cartItem = await context.CartItems
                        //    .Where(ci => ci.CartId == dd.cartID)
                        //    .Where(i => i.ItemId == dd.itemID)
                        //    .SingleOrDefaultAsync();

                        //if(cartItem == null)
                        //{
                        //    response.SetContent(false, "CartItem not found");
                        //    return response;
                        //}

                        //cart = await context.Carts
                        //    .Where(ci => ci.Id == dd.cartID)
                        //    .SingleOrDefaultAsync();

                        //if (cart == null)
                        //{
                        //    response.SetContent(false, "Cart not found");
                        //    return response;
                        //}
                        cartItem = cart.CartItems.Where(x => x.ItemId == dd.itemID).SingleOrDefault() ?? null;
                        if (cartItem != null)
                        {
                            cart.CartItems.Remove(cartItem);
                        }
                        else
                        {
                            response.SetContent(false, "CartItem not found");
                            return(response);
                        }

                        //cart.CartItems.Remove(cartItem);
                        cart = CalculateCart(cart);
                        //context.Carts.Update(cart);
                        //context.Carts.Remove(cart);
                        //await context.SaveChangesAsync();

                        await HttpContext.Session.LoadAsync();

                        HttpContext.Session.SetObject("AnnonymousCart", cart);
                        await HttpContext.Session.CommitAsync();

                        response.SetContent(true, "Deleted Successfully");
                    }
                }
                else if (userId > 0)
                {
                    if (dd.cartID != 0)
                    {
                        cartItem = await context.CartItems
                                   .Where(ci => ci.CartId == dd.cartID)
                                   .Where(i => i.ItemId == dd.itemID)
                                   .SingleOrDefaultAsync();

                        cart = await context.Carts
                               .Where(i => i.Id == dd.cartID)
                               .Where(ui => ui.UserId == userId)
                               .SingleOrDefaultAsync();

                        if (cart != null && cartItem != null)
                        {
                            cart.CartItems.Remove(cart.CartItems.FirstOrDefault(i => i.ItemId == dd.itemID));
                            cart = CalculateCart(cart);
                            context.Carts.Update(cart);
                            await context.SaveChangesAsync();

                            response.SetContent(true, "Item delete successfully.");
                        }
                        else
                        {
                            response.SetContent(false, "Could not load cart item");
                        }
                    }
                    else
                    {
                        //CART COOKIE NOT FOUND

                        /*Cart userCart = new Cart();
                         * userCart.UserId = userId;
                         * context.Carts.Add(userCart);
                         * await context.SaveChangesAsync();*/
                        response.SetContent(false, "Error trying to load cart. Please try again later");
                    }
                }
                else
                {
                    response.SetContent(false, "Invalid User id");
                }
            }
            catch (Exception xe)
            {
                response.SetContent(false, xe.Message);
            }
            return(response);
        }