Exemplo n.º 1
0
        public async Task<IHttpActionResult> PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != order.Id)
            {
                return BadRequest();
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostOrder(OrderBinding orderModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            ApplicationUser appuser = _userManager.FindById(User.Identity.GetUserId());
            Stock stock = db.Stocks              
                .Include("Product")
                .Include("Unit")
                .Include("User")
                .Include("User.User")
                .Where(st => st.Id == orderModel.StockId).FirstOrDefault();

            var order = new Order()
            {
                Stock = stock,
                FullName = orderModel.FullName,
                Phone = orderModel.Phone,
                Qty = orderModel.Qty,
                GeoPoint = new GeoPoint()
                {
                    Latitude = orderModel.GeoPoint.Latitude,
                    Longitude = orderModel.GeoPoint.Longitude,
                    Address = orderModel.GeoPoint.Address,
                    Town = orderModel.GeoPoint.Town,
                    State = orderModel.GeoPoint.State,
                    Country = orderModel.GeoPoint.Country
                },
                User = appuser
            };
            db.Orders.Add(order);
            db.SaveChanges();

            string sms1 = "http://200.31.80.34/Bolsa_Mensajes/AgroNet/CGI/ReceiverSMSFormulario.php";
            sms1 += "?to=85050";
            sms1 += String.Format("&operador={0}", GetOperator(stock.User.User.Phone));                        
            sms1 += String.Format("&mensaje=Buenas_Tienes_un_nuevo_pedido_Ref_{0}_de_{1}_{2}_de_{3}_por_{4}_{5}",
                order.Id,
                order.Qty, 
                stock.Unit.Code,
                System.Text.RegularExpressions.Regex.Replace(stock.Product.Name.Trim(), @"\s+", "_"),
                System.Text.RegularExpressions.Regex.Replace(order.FullName.Trim(), @"\s+", "_"),
                order.Phone);
            sms1 += String.Format("&movil={0}", stock.User.User.Phone);
            sms1 += "&idmessage=11111111";
            sms1 += "&concat=0";
            SendSMS(sms1);

            string sms2 = "http://200.31.80.34/Bolsa_Mensajes/AgroNet/CGI/ReceiverSMSFormulario.php";
            sms2 += "?to=85050";
            sms2 += String.Format("&operador=", order.Phone);
            sms2 += String.Format("&mensaje=Buenas_Tu_pedido_de_{0}_{1}_de_{2}_Ref_{3}_fue_creado_exitosamente_Puede_comunicarse_con_{4}_{5}",
                order.Qty,
                stock.Unit.Code,
                System.Text.RegularExpressions.Regex.Replace(stock.Product.Name.Trim(), @"\s+", "_"), 
                order.Id,
                System.Text.RegularExpressions.Regex.Replace(stock.User.User.Name.Trim(), @"\s+", "_"), 
                stock.User.User.Phone);
            sms2 += String.Format("&movil={0}", order.Phone);
            sms2 += "&idmessage=11111111";
            sms2 += "&concat=0";
            SendSMS(sms2);

            return CreatedAtRoute("DefaultApi", new { id = order.Id }, order);
        }