Example #1
0
        public override Task <RetailerResponse> AddRetailer(RetailerRequest request, ServerCallContext context)
        {
            if (request.PersonalEmail.IsEmpty() || request.Password.IsEmpty())
            {
                throw new Exception("Email and password are required");
            }
            var user = _kernel.GetEntities <User>().FirstOrDefault(user => user.PersonalEmail.ToLower() == request.PersonalEmail.Trim().ToLower());

            if (!user.IsNull())
            {
                throw new Exception("Email address already exist");
            }

            user = new User
            {
                PersonalEmail = request.PersonalEmail,
                BusinessEmail = request.BusinessEmail,
                City          = request.City,
                ContactNumber = request.ContactNumber,
                Line1         = request.Line1,
                Line2         = request.Line2,
                Name          = request.Name,
                Password      = request.Password,
                State         = request.State,
                UserType      = UserType.Retailer,
                Zipcode       = request.Zipcode
            };
            _kernel.AddEntity(entity: user, saveChanges: true);
            ValidateUserType(user);
            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(user: user)));
        }
        private void HandleRetailerRequest(RetailerRequest request)
        {
            WarehouseProgram.RecieveMessage(id, request.Order.ProductIds[0], country.ToString());
            WarehouseReply reply = new WarehouseReply()
            {
                Order = request.Order
            };

            Product p = products.FirstOrDefault(x => x.ProductId == request.Order.ProductIds[0]);

            if (p != null && p.ItemsInStock > 0)
            {
                reply.Order.IsAvailable = true;
                if (request.Order.CountryCode.Equals(country))
                {
                    reply.Order.DeliveryTime   = 2;
                    reply.Order.ShippingCharge = 5;
                }
                else
                {
                    reply.Order.DeliveryTime   = 4;
                    reply.Order.ShippingCharge = 10;
                }
            }
            else
            {
                reply.Order.IsAvailable = false;
            }
            bus.Send <WarehouseReply>("warehouse.retailer", reply);
            WarehouseProgram.SendMessage(id, reply.Order.IsAvailable);
        }
 public IEnumerable<KeyValuePair<string, string>> Get(RetailerRequest request)
 {
     ICollection<KeyValuePair<string, string>> response = new Collection<KeyValuePair<string, string>>();
     response.Add(new KeyValuePair<string, string>("1", "Best Buy"));
     response.Add(new KeyValuePair<string, string>("2", "Frys"));
     response.Add(new KeyValuePair<string, string>("3", "Wal Mart"));
     response.Add(new KeyValuePair<string, string>("4", "Target"));
     response.Add(new KeyValuePair<string, string>("5", "Safeway"));
     response.Add(new KeyValuePair<string, string>("6", "Knob Hill"));
     response.Add(new KeyValuePair<string, string>("7", "Luckys"));
     return response;
 }
Example #4
0
        public async Task <RetailerResponse> AddRetailer([Required] RetailerRequest request)
        {
            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Retailer.RetailerClient(channel);
                _logger.LogDebug("Grpc post Retailer request {@request}", request);
                var retailer = await client.AddRetailerAsync(request);
                await UpdateProductRetailer(retailer);
                return(retailer);
            });

            return(response);
        }
Example #5
0
        public IEnumerable <KeyValuePair <string, string> > Get(RetailerRequest request)
        {
            ICollection <KeyValuePair <string, string> > response = new Collection <KeyValuePair <string, string> >();

            response.Add(new KeyValuePair <string, string>("1", "Best Buy"));
            response.Add(new KeyValuePair <string, string>("2", "Frys"));
            response.Add(new KeyValuePair <string, string>("3", "Wal Mart"));
            response.Add(new KeyValuePair <string, string>("4", "Target"));
            response.Add(new KeyValuePair <string, string>("5", "Safeway"));
            response.Add(new KeyValuePair <string, string>("6", "Knob Hill"));
            response.Add(new KeyValuePair <string, string>("7", "Luckys"));
            return(response);
        }
 private static void HandleWareHouseMessage(WarehouseReply warehouseMsg)
 {
     if (CustomerRequests.Find(x => x.CustomerId == warehouseMsg.Order.CustomerId) != null)
     {
         if (!HasPublished[warehouseMsg.Order.CustomerId])
         {
             Console.WriteLine("Recieved message from a local warehouse.");
             if (warehouseMsg.Order.IsAvailable)
             {
                 Console.WriteLine("Product is available..\nSending to client..");
                 RetailerReply msg = new RetailerReply()
                 {
                     ProductId = warehouseMsg.Order.ProductIds[0], IsAvailable = warehouseMsg.Order.IsAvailable
                 };
                 Bus.Send <RetailerReply>($"retailer.client.{warehouseMsg.Order.CustomerId}", msg);
                 CustomerRequests.RemoveAll(x => x.CustomerId == warehouseMsg.Order.CustomerId);
                 WarehouseReplyLimiter.Remove(warehouseMsg.Order.CustomerId);
                 HasPublished.Remove(warehouseMsg.Order.CustomerId);
                 Console.WriteLine($"Response sent to customer with client id: {warehouseMsg.Order.CustomerId}");
             }
             else
             {
                 Console.WriteLine("Product not available.. Publishing to all warehouses..");
                 RetailerRequest req = new RetailerRequest()
                 {
                     Order = warehouseMsg.Order
                 };
                 Bus.Publish <RetailerRequest>(req, "retailer.warehouses");
                 HasPublished[warehouseMsg.Order.CustomerId] = true;
             }
         }
         else
         {
             Console.WriteLine("Recieved message from one of all warehouses..");
             if (warehouseMsg.Order.IsAvailable || ++WarehouseReplyLimiter[warehouseMsg.Order.CustomerId] >= MAX_WAREHOUSES)
             {
                 RetailerReply reply = new RetailerReply()
                 {
                     ProductId = warehouseMsg.Order.ProductIds[0], IsAvailable = warehouseMsg.Order.IsAvailable
                 };
                 Bus.Send <RetailerReply>($"retailer.client.{warehouseMsg.Order.CustomerId}", reply);
                 CustomerRequests.RemoveAll(x => x.CustomerId == warehouseMsg.Order.CustomerId);
                 WarehouseReplyLimiter.Remove(warehouseMsg.Order.CustomerId);
                 HasPublished.Remove(warehouseMsg.Order.CustomerId);
                 Console.WriteLine($"Response sent to customer with client id: {warehouseMsg.Order.CustomerId}");
             }
         }
     }
 }
        private static void HandleCustomerRequest(CustomerRequest req)
        {
            CustomerRequests.Add(req);
            HasPublished.Add(req.CustomerId, false);
            WarehouseReplyLimiter.Add(req.CustomerId, 0);
            Console.WriteLine($"Message recieved on (client.retailer). Client id: '{req.CustomerId}', Location: '{req.CountryCode}'");
            Order o = new Order {
                CustomerId = req.CustomerId, CountryCode = req.CountryCode
            };

            o.ProductIds.Add(req.ProductId);
            var retailerRequest = new RetailerRequest()
            {
                Order = o
            };

            Bus.Publish <RetailerRequest>(retailerRequest, $"retailer.warehouses.{req.CountryCode}");
        }