Example #1
0
        public ActionResult DetailsHandleError(int id)
        {
            var customer = _customerServices.GetCustomerById(id);

            if (customer == null)
            {
                // Create own exception class
                throw new Exception("Resource not found");
            }
            return(View("Details", customer));
        }
Example #2
0
        // GET: Customers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Customer customer = service.GetCustomerById(id.Value);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            return(View(customer));
        }
Example #3
0
        public IActionResult CustomerDetail(int id)
        {
            var find      = customerServices.GetCustomerById(id);
            var viewModel = new Customers()
            {
                Tc       = find.Tc,
                Name     = find.Name,
                Surname  = find.Surname,
                Telefone = find.Telefone,
                Adress   = find.Adress,
                City     = find.City
            };

            return(View(viewModel));
        }
Example #4
0
        public async Task <IActionResult> GetById(int id)
        {
            var result = await _customerService.GetCustomerById(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
        //// GET api/product/5
        public HttpResponseMessage Get(int id)
        {
            // if any info need to log
            // Logger.Info("Customer.Get");
            var product = _customerServices.GetCustomerById(id);

            if (product != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, product));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No product found for this id"));
        }
        public IActionResult GetGetCustomerById(Guid id)
        {
            var customer = _customerServices.GetCustomerById(id);

            if (customer != null)
            {
                return(Ok(customer));
            }
            else
            {
                return(NoContent());
            }
        }
        public CustomerServiceWrapper(ICustomerServices service)
        {
            //defining the mapping for AutoMapper
            Mapper.CreateMap<IList<CustomerDto>, IList<CloudyBank.PortableServices.Customers.CustomerDto>>();
            Mapper.CreateMap<CustomerDto, CloudyBank.PortableServices.Customers.CustomerDto>();

            this.service = service;

            //defining the delegate
            this.CustomerByIDDelegate = (i) => {
                App.Bind();
                return Mapper.Map<CustomerDto, CloudyBank.PortableServices.Customers.CustomerDto>(service.GetCustomerById(i));
            };
        }
Example #8
0
        public async Task <Result> AddOrder(OrderViewModel order)
        {
            try
            {
                if (order.OrderItems.Count == 0)
                {
                    return new Result()
                           {
                               Success = false, Message = "O Pedido deve ter ao menos uma pizza."
                           }
                }
                ;

                if (order.OrderItems.Count > 10)
                {
                    return new Result()
                           {
                               Success = false, Message = "O Pedido máximo é de 10 pizzas."
                           }
                }
                ;

                if (order.OrderItems.Any(a => a.OrderItemSplits.Where(w => w.OrderItemId == a.Id).Count() > 2))
                {
                    return new Result()
                           {
                               Success = false, Message = "Cada pizza podem ter no máximo 2 sabores."
                           }
                }
                ;

                // Se o Pedido tiver um cliente cadastrado pega os dados do cliente.
                if (order.CustomerId.HasValue)
                {
                    var _customerDB = await _customerServices.GetCustomerById(order.CustomerId.Value);

                    if (_customerDB != null)
                    {
                        order.OrderDelivery.ZipCode  = _customerDB.ZipCode;
                        order.OrderDelivery.Address1 = _customerDB.Address1;
                        order.OrderDelivery.Number   = _customerDB.Number;
                        order.OrderDelivery.Address2 = _customerDB.Address2;
                        order.OrderDelivery.District = _customerDB.District;
                        order.OrderDelivery.City     = _customerDB.City;
                        order.OrderDelivery.State    = _customerDB.State;
                        order.OrderDelivery.Country  = _customerDB.Country;
                    }
                }

                // Totaliza o pedido.
                double orderTotal = 0;
                foreach (var item in order.OrderItems)
                {
                    double orderItemTotal = 0;
                    foreach (var itemSplit in item.OrderItemSplits)
                    {
                        var price = itemSplit.Pizza.Price;
                        if (string.IsNullOrEmpty(itemSplit.Pizza.Flavor))
                        {
                            var pizzaDB = await _pizzaServices.PizzaById(itemSplit.Pizza.Id);

                            price             = pizzaDB.Price;
                            itemSplit.PizzaId = pizzaDB.Id;
                            itemSplit.Price   = price;
                            itemSplit.Pizza   = null;
                        }

                        orderItemTotal += item.SplitPie ? price / 2 : price;
                    }

                    item.Total  = orderItemTotal;
                    orderTotal += item.Total;
                }

                order.Total = orderTotal;

                await _context.Orders.AddAsync(_mapper.Map <Order>(order));

                await _context.SaveChangesAsync();

                return(new Result()
                {
                    Success = true, Message = "Pedido incluído com sucesso!"
                });
            }
            catch (Exception e)
            {
                return(new Result()
                {
                    Success = false, Message = e.Message
                });
            }
        }
Example #9
0
        public CustomerServiceWrapper(ICustomerServices service)
        {
            //defining the mapping for AutoMapper
            Mapper.CreateMap <IList <CustomerDto>, IList <CloudyBank.PortableServices.Customers.CustomerDto> >();
            Mapper.CreateMap <CustomerDto, CloudyBank.PortableServices.Customers.CustomerDto>();

            this.service = service;

            //defining the delegate
            this.CustomerByIDDelegate = (i) => {
                App.Bind();
                return(Mapper.Map <CustomerDto, CloudyBank.PortableServices.Customers.CustomerDto>(service.GetCustomerById(i)));
            };
        }