Пример #1
0
        //Update product
        //Input: productDTO, clientId
        //Output: result in string
        public static string updateProduct(productDTO product_req, string clientId)
        {
            SwapDbConnection db       = new SwapDbConnection();
            product          sameName = db.products.FirstOrDefault(p => p.name == product_req.name && p.business_id == product_req.business_id &&
                                                                   p.business.business_owner_id == clientId && p.product_id != product_req.product_id);

            if (sameName != null)
            {
                return("same");
            }
            product product = db.products.FirstOrDefault(p => p.business_id == product_req.business_id && p.product_id == product_req.product_id && p.business.business_owner_id == clientId);

            if (product == null)
            {
                return("notExists");
            }
            product.price               = product_req.price;
            product.name                = product_req.name;
            product.description         = product_req.description;
            product.discount            = product_req.discount;
            product.discount_end_date   = product_req.discount_end_date;
            product.discount_start_date = product_req.discount_start_date;
            db.SaveChanges();
            return("ok");
        }
Пример #2
0
        public decimal SummOfGoodsSold()
        {
            decimal summ = 0;

            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                List <orderDTO> orders = new List <orderDTO>();

                orders = mapper.Map <List <orderDTO> >(db.C_order_.ToList());
                DateTime now = DateTime.Now;

                foreach (orderDTO order in orders)
                {
                    //   if ((now - order.sell_time).TotalDays < 30)
                    if (now.Month == order.sell_time.Month)

                    {
                        product_id prod = db.product_id
                                          .Where(u => u.product_id1 == order.product_id)
                                          .FirstOrDefault();
                        productDTO new_prod = mapper.Map <productDTO>(prod);

                        summ += new_prod.price;
                    }
                }//дали розбити .сума куплениї можна прото поточний місяць і з знижкою 3 параметри брати ід продукт ід і знижку і ставити там
            }
            return(summ);
        }
Пример #3
0
        public void Alterar(productDTO product)
        {
            string sql = string.Format($@"UPDATE product SET name =
        '{product.name}',
         description = '{product.description}',
        value = '{product.value}',
        providerID = '{product.providerID}',
        categoryID = '{product.categoryID}',
        photo = '{product.photo}',
        quantity Stok = '{product.quantityStok}';");

            con.ExecuteSQL(sql)
        }
Пример #4
0
        //method CRUD

        public void Inserir(productDTO product)
        {
            string sql = string.Format($@ "INSERT INTO product VALUES (null," { product.Name }
                                       "," { product.Description }
                                       "," { product.Value }
                                       "," { product.ProviderID }
                                       "," { product.CategoryID }
                                       "," { product.Photo }
                                       "," { product.QuantityStok }
                                       ");");

            con.ExecuteSQL(sql);
        }
Пример #5
0
        //Add new product
        //Input: productDTO, ClientId
        //Output: productDTO
        public static productDTO AddProduct(productDTO req, string ClientId)
        {
            SwapDbConnection db       = new SwapDbConnection();
            business         business = db.businesses.FirstOrDefault(b => b.business_owner_id == ClientId && b.place_id == req.business_id);

            if (business == null)
            {
                return(null);
            }
            if (business.products.FirstOrDefault(p => p.name == req.name) != null)
            {
                return(null);
            }

            product product_obj = new product()
            {
                product_id          = IdService.generateID("product_id"),
                creation_date       = DateTime.Now,
                is_active           = req.is_active,
                name                = req.name,
                business_id         = req.business_id,
                discount            = req.discount,
                discount_start_date = req.discount_start_date,
                discount_end_date   = req.discount_end_date,
                price               = req.price,
                description         = req.description
            };

            db.products.Add(product_obj);
            db.SaveChanges();

            return(new productDTO
            {
                business_id = req.business_id,
                creation_date = product_obj.creation_date,
                description = product_obj.description,
                discount = product_obj.discount,
                discount_end_date = product_obj.discount_end_date,
                discount_start_date = product_obj.discount_start_date,
                is_active = product_obj.is_active,
                name = product_obj.name,
                price = product_obj.price,
                product_id = product_obj.product_id
            });
        }
Пример #6
0
 public HttpResponseMessage ChangeProducActive([FromBody] productDTO products, string clientId)
 {
     try
     {
         SwapDbConnection db = new SwapDbConnection();
         product          slected_products = db.products.FirstOrDefault(x => x.business_id == products.business_id && x.product_id == products.product_id && x.business.business_owner_id == clientId);;
         if (slected_products == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no product with that id :" + products.product_id));
         }
         slected_products.is_active = products.is_active;
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, true));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
     }
 }
Пример #7
0
        //Not in used
        public static productDTO GetProductByid(string product_id)
        {
            SwapDbConnection db          = new SwapDbConnection();
            productDTO       product_obj = db.products.Select(x => new productDTO()
            {
                business_id         = x.business_id,
                creation_date       = x.creation_date,
                description         = x.description,
                is_active           = x.is_active,
                name                = x.name,
                discount_end_date   = x.discount_end_date,
                discount            = x.discount,
                discount_start_date = x.discount_start_date,
                price               = x.price,
                product_id          = x.product_id
            })
                                           .FirstOrDefault(x => x.product_id == product_id);

            return(product_obj);
        }
Пример #8
0
        public HttpResponseMessage AddProduct([FromBody] productDTO req, string clientId)
        {
            try
            {
                if (req.name != null && req.description != null)
                {
                    productDTO product = ProductService.AddProduct(req, clientId);
                    if (product != null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, product));
                    }
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "There is a product with this name:" + req.name));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Missing prameters in your request"));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
            }
        }
Пример #9
0
 public HttpResponseMessage UpdateProduct([FromBody] productDTO req, string clientId)
 {
     try
     {
         SwapDbConnection db       = new SwapDbConnection();
         string           response = ProductService.updateProduct(req, clientId);
         if (response == "same")
         {
             return(Request.CreateResponse(HttpStatusCode.Conflict, "There is a product with that name :" + req.name));
         }
         if (response == "notExists")
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "There no product with that id :" + req.product_id));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, "The product was changed"));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
     }
 }
Пример #10
0
        private void testDoSale()
        {
            CustomerSalesServicesClient client = new CustomerSalesServicesClient();

            doSaleRequest request = new doSaleRequest();

            customer c = new customer();

            c.birthDate          = new DateTime(1984, 3, 3);
            c.birthDateSpecified = true;

            addressDTO add = new addressDTO();

            add.addressDetail     = "Rua 1";
            add.type              = addressType.RESIDENTIAL;
            add.typeSpecified     = true;
            add.addressNumber     = "123";
            add.addressPostalCode = "06871120";
            add.city              = "Embu";
            add.neighborhood      = "Marilú";
            add.state             = "SP";

            phoneDTO phone = new phoneDTO();

            phone.phoneNumber   = "1143216363";
            phone.type          = phoneType.RESIDENTIAL;
            phone.typeSpecified = true;

            c.fullName        = "Teste Abobrinha";
            c.gender          = gender.MALE;
            c.genderSpecified = true;

            identityDTO iden = new identityDTO();

            iden.documentType          = document.CPF;
            iden.documentTypeSpecified = true;
            iden.documentValue         = "40614102022";


            c.maritalStatus          = maritalStatus.SINGLE;
            c.maritalStatusSpecified = true;
            //criar novo contato para celular e repetir
            //cus.contacts[1].phone.phoneNumber = segurosuppro.Celular;
            //cus.contacts[1].phone.type = phoneType.MOBILE;

            cardPaymentDTO card = new cardPaymentDTO();

            card.cardDisplayName       = "THIAGO SANTANA";
            card.cardFlag              = "luiza";
            card.cardNumber            = "5307804589564512";
            card.cardSecurityCode      = "456";
            card.cardValidity          = new DateTime(1985, 1, 26);
            card.cardValiditySpecified = true;
            card.cardValue             = Convert.ToDecimal("19,90");
            card.cardValueSpecified    = true;

            productDTO prod = new productDTO();

            prod.descripton  = "CARTÃO PROTEGIDO";
            prod.ID          = 25;
            prod.IDSpecified = true;

            contactDTO cc = new contactDTO();

            cc.address = add;
            cc.phone   = phone;

            contactDTO[] contatos = new contactDTO[] { cc };
            c.contacts = contatos;
            c.identity = iden;

            paymentMethod payM = new paymentMethod();

            payM.cardPayment = card;

            identityDTO idensales = new identityDTO();

            idensales.documentType          = document.CPF;
            idensales.documentTypeSpecified = true;
            idensales.documentValue         = "10752104969";

            loginDTO log = new loginDTO();

            log.username = "******";
            log.password = "******";

            partner part = new partner();

            part.ID          = 001;
            part.IDSpecified = true;

            salesman salman = new salesman();

            salman.identity     = idensales;
            salman.login        = log;
            salman.partner      = part;
            salman.operatorName = "Saulo Mezencio";

            sale sa = new sale();

            sa.customer      = c;
            sa.paymentMethod = payM;
            sa.product       = prod;
            sa.salesman      = salman;

            request.sale = sa;

            doSaleResponse response = null;

            try {
                response = client.doSale(request);

                Console.WriteLine("Response = " + response);
                Console.WriteLine("PARANDO PARA VISUALIZAR JANELA");
            } catch (Microsoft.Web.Services3.ResponseProcessingException exR) {
                Console.WriteLine("Exception to call service FAULT: " + exR.Response.OuterXml);
                Console.WriteLine("PARANDO PARA VISUALIZAR JANELA ANTERIOR");
            }/* catch (Exception ex) {
              * Console.WriteLine("Exception : " + ex);
              * Console.WriteLine("PARANDO PARA VISUALIZAR JANELA");
              * }*/
        }
Пример #11
0
        public void Excluir(productDTO product)
        {
            string sql = string.Format($@"DELETE FROM product WHERE id = { product.id};");

            con.ExecuteSQL(sql);
        }