コード例 #1
0
        /// <summary>
        /// places a mail order Adds an item to the system
        /// </summary>
        /// <param name="body">Inventory item to add</param>
        /// <returns></returns>
        public void PlaceMailOrder(MailOrder body)
        {
            var path = "/mail/order";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            postBody = ApiClient.Serialize(body);                         // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { "apiKeyAuth" };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PlaceMailOrder: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PlaceMailOrder: " + response.ErrorMessage, response.ErrorMessage);
            }

            return;
        }
コード例 #2
0
        public virtual IActionResult PlaceMailOrder([FromBody] MailOrder body)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200);

            //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(400, default(InlineResponse401));

            //TODO: Uncomment the next line to return response 409 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(409, default(InlineResponse401));

            //TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(401, default(InlineResponse401));

            throw new NotImplementedException();
        }
コード例 #3
0
        public void TestMethod1()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Order, OrderDto>()
                .Include <OnlineOrder, OnlineOrderDto>()
                .Include <MailOrder, MailOrderDto>();
                cfg.CreateMap <OnlineOrder, OnlineOrderDto>();
                cfg.CreateMap <MailOrder, MailOrderDto>();
            });

            var mapper = config.CreateMapper();

            var mailOrder = new MailOrder()
            {
                NewId = 1
            };
            var mapped = mapper.Map <OrderDto>(mailOrder);

            mapped.ShouldBeType <MailOrderDto>();
        }
コード例 #4
0
        public void TestMethod1()
        {
            Mapper.Reset();

            Mapper.CreateMap <Order, OrderDto>()
            .Include <OnlineOrder, OnlineOrderDto>()
            .Include <MailOrder, MailOrderDto>();
            Mapper.CreateMap <OnlineOrder, OnlineOrderDto>();
            Mapper.CreateMap <MailOrder, MailOrderDto>();
            Mapper.Configuration.Seal();

            //Mapper.AssertConfigurationIsValid();

            var mailOrder = new MailOrder()
            {
                NewId = 1
            };
            var mapped = Mapper.Map <OrderDto>(mailOrder);

            mapped.ShouldBeOfType <MailOrderDto>();
        }
コード例 #5
0
        public JsonResult Payment(long id)
        {
            var         message     = "";
            UserSession userSession = SessionHelper.GetSession(AppSettingConstant.LoginSessionCustomer) as UserSession;

            if (userSession != null)
            {
                var user = _userRepository.Find(u => u.Status.Equals(Status.Active) && u.Username.Equals(userSession.Username));
                if (user != null)
                {
                    var orderSession = SessionHelper.GetSession(AppSettingConstant.CheckOutSession) as Order;
                    if (orderSession != null)
                    {
                        var card = user.Customer.CreditCards.FirstOrDefault(c => c.CreditCardId == id & c.Status == Status.Active);
                        if (card != null)
                        {
                            var bankCredit = _bankService.CheckCard(AESEncrytDecry.DecryptStringAES(card.CreditNumber), card.Expire, card.CVC);
                            if (bankCredit != null)
                            {
                                var    cart      = SessionHelper.GetSession(AppSettingConstant.CartSession) as List <CartItem>;
                                var    amount    = cart.Sum(c => c.Quantity * (c.Product.ProductPrice + c.Material.Price));
                                string rootPath  = "~/Images/Upload/";
                                var    extenPath = string.Format("{0}/{1}_{2}", user.Username, DateTime.Now.Second, DateTime.Now.Millisecond);
                                string path      = Server.MapPath(rootPath + extenPath); //Path

                                //Check if directory exist
                                if (!System.IO.Directory.Exists(path))
                                {
                                    System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist
                                }
                                foreach (var item in cart as List <CartItem> )
                                {
                                    string imgPath    = Path.Combine(path, item.ImageTitle);
                                    byte[] imageBytes = Convert.FromBase64String(item.Image);
                                    System.IO.File.WriteAllBytes(imgPath, imageBytes);
                                }
                                if (bankCredit.Balance >= amount)
                                {
                                    bankCredit.Balance -= amount.Value;
                                    List <OrderDetail> orderDetails = new List <OrderDetail>();
                                    foreach (var item in cart)
                                    {
                                        OrderDetail orderDetail = new OrderDetail()
                                        {
                                            MaterialId = item.Material.Id,
                                            ProductId  = item.Product.ProductId,
                                            Quantity   = item.Quantity,
                                            Option     = item.Option,
                                            Image      = item.ImageTitle
                                        };
                                        orderDetails.Add(orderDetail);
                                    }
                                    orderSession.CreditCardId = card.CreditCardId;
                                    orderSession.CreatedAt    = DateTime.Now;
                                    orderSession.Status       = OrderStatus.Pending;
                                    orderSession.CustomerId   = user.CustomerId;
                                    orderSession.FolderImage  = extenPath;
                                    orderSession.IsCancel     = true;
                                    var transac = _orderServiceTrans.TransactionPayment(orderSession, orderDetails, bankCredit);
                                    if (transac != null)
                                    {
                                        var       addressDetails = _addressRepository.Find(a => a.AddressId == orderSession.AddressId);
                                        MailOrder model          = new MailOrder(cart, transac.OrderId, user.Email, addressDetails.AddressDetails, user.Customer.CustomerName, card.CreditNumber, transac.FolderImage, amount.Value, transac.PhoneNumber);
                                        var       body           = ViewToString.RenderRazorViewToString(this, "MailOrder", model);
                                        var       bodyAdmin      = ViewToString.RenderRazorViewToString(this, "MailBackAdmin", model);
                                        string    mailAdmin      = ConfigurationManager.AppSettings["mailadmin"];
                                        Task.Factory.StartNew((() =>
                                        {
                                            SendEmail.Send(mailAdmin, bodyAdmin, "New order notification!");
                                            SendEmail.Send(user.Email, body, "Your order information!");
                                        }));
                                        SessionHelper.Delete(AppSettingConstant.CartSession);
                                        TempData["Success"] = "Order Success";
                                        return(Json(new { status = true, message, transac.OrderId }, JsonRequestBehavior.AllowGet));
                                    }
                                    else
                                    {
                                        if (System.IO.File.Exists(path))
                                        {
                                            System.IO.File.Delete(path);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(Json(new { status = false, message }, JsonRequestBehavior.AllowGet));
        }