コード例 #1
0
        public IHttpActionResult Put(int id, [FromBody] CartProdModel cartProdModel)
        {
            var  result = new Result <String>();
            Type type   = typeof(CartProd);

            using (var db = new jupiterEntities())
            {
                var a = db.CartProds.Where(x => x.Id == id).Select(x => x).FirstOrDefault();
                if (a == null)
                {
                    return(Json(DataNotFound(result)));
                }
                UpdateTable(cartProdModel, type, a);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    result.IsSuccess    = false;
                    result.ErrorMessage = e.Message;
                    return(Json(result));
                }
                return(Json(result));
            }
        }
コード例 #2
0
        private void AddCartItem(Cart cart, CartProdModel s)
        {
            CartProd cartProd = new CartProd();

            cartProd.Quantity = s.Quantity;
            cartProd.CartId   = s.CartId;
            cartProd.Price    = s.Price;
            cartProd.Title    = s.Title;
            if (s.ProdId != null)
            {
                if (s.ProdDetailId == null)
                {
                    cartProd.ProdId = s.ProdId;
                }
                else if (s.ProdDetailId != null)
                {
                    cartProd.ProdId       = s.ProdId;
                    cartProd.ProdDetailId = s.ProdDetailId;
                }
            }
            else if (s.PackId != null)
            {
                cartProd.PackId = s.PackId;
            }
            else if (s.SaleProdId != null)
            {
                cartProd.SaleProdId = s.SaleProdId;
            }
            _context.CartProd.Add(cartProd);
        }
コード例 #3
0
        public IHttpActionResult Get(int id)
        {
            var           result        = new Result <CartProdModel>();
            CartProdModel cartProdModel = new CartProdModel();

            using (var db = new jupiterEntities())
            {
                var a = db.CartProds.Where(x => x.Id == id).Select(x => x).FirstOrDefault();
                if (a == null)
                {
                    return(Json(DataNotFound(result)));
                }
                Mapper.Map(a, cartProdModel);
                result.Data = cartProdModel;
                return(Json(result));
            }
        }
コード例 #4
0
        public IHttpActionResult Post([FromBody] CartProdModel cartProdModel)
        {
            var result = new Result <String>();

            using (var db = new jupiterEntities())
            {
                CartProd cartProd = new CartProd();
                Mapper.Map(cartProdModel, cartProd);
                try
                {
                    db.CartProds.Add(cartProd);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    result.ErrorMessage = e.Message;
                    result.IsSuccess    = false;
                    return(Json(result));
                }
                return(Json(result));
            }
        }
コード例 #5
0
        public async Task <IActionResult> PutCartProd(int id, CartProdModel cartProdModel)
        {
            var  result         = new Result <string>();
            Type cartProdType   = typeof(CartProd);
            var  updateCartProd = await _context.CartProd.Where(x => x.Id == id).FirstOrDefaultAsync();

            if (updateCartProd == null)
            {
                return(NotFound(DataNotFound(result)));
            }
            UpdateTable(cartProdModel, cartProdType, updateCartProd);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                result.ErrorMessage = e.Message;
                result.IsSuccess    = false;
                return(BadRequest(result));
            }
            return(Ok(result));
        }
コード例 #6
0
        private void AddProdTime(Cart cart, CartProdModel s, [Optional] PackageProductModel prod)
        {
            ProductTimetable prodTime = new ProductTimetable();

            prodTime.CartId    = s.CartId;
            prodTime.IsActive  = 1;
            prodTime.BeginDate = cart.EventStartDate;
            prodTime.EndDate   = cart.EventEndDate;
            if (s.ProdId != null)
            {
                if (s.ProdDetailId == null)
                {
                    prodTime.ProdId   = s.ProdId;
                    prodTime.Quantity = s.Quantity;
                }
                else if (s.ProdDetailId != null)
                {
                    prodTime.ProdDetailId = s.ProdDetailId;
                    prodTime.Quantity     = s.Quantity;
                }
            }
            else if (s.PackId != null)
            {
                if (prod.ProdDetailId == null)
                {
                    prodTime.ProdId   = prod.ProdId;
                    prodTime.Quantity = prod.Quantity * s.Quantity;
                }
                else if (prod.ProdDetailId != null)
                {
                    prodTime.ProdDetailId = prod.ProdDetailId;
                    prodTime.Quantity     = prod.Quantity * s.Quantity;
                }
            }
            _context.ProductTimetable.Add(prodTime);
        }