Ejemplo n.º 1
0
        public ActionResult IncluirVendedor(Model.Entities.Vendor Vendor, int CustomerID)
        {
            try
            {
                context = new DALContext();

                context.Vendors.Create(Vendor);
                context.SaveChanges();

                context.VendorsCustomer.Create(new VendorsCustomer()
                {
                    CustomerID = CustomerID,
                    VendorID   = Vendor.Id
                });

                context.SaveChanges();

                var Customer = context.Customers.Find(p => p.Id == CustomerID);

                Customer.VendorId = Vendor.Id;
                context.Customers.Update(Customer);
                context.SaveChanges();

                return(Content(String.Format("{0}", Vendor.Id)));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public Status Create(Status Status)
        {
            var ret = _Dbcontext.Status.Create(Status);

            _Dbcontext.SaveChanges();

            return(ret);
        }
Ejemplo n.º 3
0
        public void AddVitalData()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.VitalData.Create(_vitalData);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_vitalData, _context.VitalData.GetById(_vitalData.VitalID));
            }
        }
Ejemplo n.º 4
0
        public void AddNutritionLog()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.NutritionLog.Create(_nutritionLog);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_nutritionLog, _context.NutritionLog.GetAll().LastOrDefault());
                Assert.AreEqual(_nutritionLog, _context.NutritionLog.GetById(_nutritionLog.NLID));
            }
        }
Ejemplo n.º 5
0
        public void AddProfile()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.Profile.Create(_profile);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_profile, _context.Profile.GetAll().LastOrDefault());
                Assert.AreEqual(_profile, _context.Profile.GetById(_profile.ProfileID));
            }
        }
        public void AddActivity()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.Activity.Create(_activity);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_activity, _context.Activity.GetAll().LastOrDefault());
                Assert.AreEqual(_activity, _context.Activity.GetById(_activity.ActID));
            }
        }
        public void AddFood()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.Food.Create(_food);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_food, _context.Food.GetAll().LastOrDefault());
                Assert.AreEqual(_food, _context.Food.GetById(_food.FoodID));
            }
        }
Ejemplo n.º 8
0
        public void AddPortion()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                _context.Portion.Create(_portion);
                _context.SaveChanges();

                // Assert
                Assert.AreEqual(_portion, _context.Portion.GetAll().LastOrDefault());
                Assert.AreEqual(_portion, _context.Portion.GetById(_portion.PortionID));
            }
        }
Ejemplo n.º 9
0
        public ActionResult ContatoSave(Contact model)
        {
            context = new DALContext();

            try
            {
                model.RegisterDate = DateTime.Now;
                model.LastUpdate   = DateTime.Now;

                if (ModelState.IsValid)
                {
                    if (model.VendorID == null)
                    {
                        model.VendorID = 1;
                    }

                    if (model.Id > 0)
                    {
                        context.Contacts.Update(model);
                    }
                    else
                    {
                        context.Contacts.Create(model);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Contato cadastrado com sucesso.";

            return(RedirectToAction("Contatos"));
        }
Ejemplo n.º 10
0
        public ActionResult ClientesSave(Customer model)
        {
            context = new DALContext();

            try
            {
                model.RegisterDate = DateTime.Now;
                model.LastUpdate   = DateTime.Now;

                if (model.Id > 0)
                {
                    context.Customers.Update(model);
                }
                else
                {
                    context.Customers.Create(model);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Cliente cadastrado com sucesso.";

            return(RedirectToAction("Clientes"));
        }
Ejemplo n.º 11
0
        public ActionResult CondicaoPagamentoSave(PaymentTerm PaymentTerm)
        {
            context = new DALContext();

            try
            {
                //prod.AliqICMS = 3;
                //prod.CombinedProduct = false;
                //prod.MinimumStockAlert = 50;
                if (PaymentTerm.Id > 0)
                {
                    context.PaymentTerms.Update(PaymentTerm);
                }
                else
                {
                    context.PaymentTerms.Create(PaymentTerm);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Condição de Pagamento cadastrada com sucesso.";

            return(RedirectToAction("CondicaoPagamento"));
        }
Ejemplo n.º 12
0
        public ActionResult ContatosEmailSave(UserAdressBook model)
        {
            context = new DALContext();

            try
            {
                if (ModelState.IsValid)
                {
                    model.Username = User.Identity.Name;

                    if (model.Id > 0)
                    {
                        context.AddressBooks.Update(model);
                    }
                    else
                    {
                        context.AddressBooks.Create(model);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Contato cadastrado com sucesso.";

            return(RedirectToAction("ContatosEmailLista"));
        }
Ejemplo n.º 13
0
        public JsonResult VincularFornecedorProduto(int ProviderID, int ProductID, long codigoProdutoFornecedor, string modeloFabricante)
        {
            try
            {
                context = new DALContext();

                var objProductProvider = new ProductProvider()
                {
                    ProductID     = ProductID,
                    ProviderID    = ProviderID,
                    Code          = codigoProdutoFornecedor,
                    IsActive      = true,
                    ModelProvider = modeloFabricante
                };

                context.ProductProviders.Create(objProductProvider);
                context.SaveChanges();

                return(Json(new { erro = false }));
            }
            catch (Exception ex)
            {
                return(Json(new { erro = true, msg = ex.Message }));
            }
        }
Ejemplo n.º 14
0
        public ActionResult FornecedorSave(Provider model)
        {
            context = new DALContext();

            try
            {
                model.RegisterDate     = DateTime.Now;
                model.LastUpdate       = DateTime.Now;
                model.PhoneCode        = 13;
                model.CommercialPolicy = 0;
                model.Discount         = 0;

                if (model.Id > 0)
                {
                    context.Providers.Update(model);
                }
                else
                {
                    context.Providers.Create(model);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Fornecedor cadastrado com sucesso.";

            return(RedirectToAction("Fornecedores"));
        }
Ejemplo n.º 15
0
        public ActionResult VendedorSave(Vendor model)
        {
            context = new DALContext();

            try
            {
                if (model.PercentCommission <= 0)
                {
                    model.PercentCommission = 5;
                }

                if (model.Id > 0)
                {
                    context.Vendors.Update(model);
                }
                else
                {
                    context.Vendors.Create(model);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.Message = "Vendedor cadastrado com sucesso.";

            return(RedirectToAction("Vendedores"));
        }
Ejemplo n.º 16
0
        public ActionResult IncluirCliente(Model.Entities.Customer Customer)
        {
            try
            {
                context = new DALContext();

                Customer.Document = Customer.Document.Replace(".", "").Replace("-", "").Replace("/", "");

                context.Customers.Create(Customer);
                context.SaveChanges();

                var CustomerList = context.Customers.All()
                                   .Select(p => new
                {
                    p.Id,
                    p.CompanyName
                })
                                   .OrderBy(p => p.CompanyName).ToList();

                var CustomerListJSON = new JavaScriptSerializer().Serialize(CustomerList);

                return(Content(String.Format("{0};{1}", Customer.Id, CustomerListJSON)));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 17
0
        public ActionResult DeletePurchaseOrderItem(int PurchaseOrderItemID)
        {
            context = new DALContext();
            context.PurchaseOrderItem.Delete(p => p.Id == PurchaseOrderItemID);
            context.SaveChanges();

            return(Content("Item Excluído com Sucesso!"));
        }
Ejemplo n.º 18
0
        public ActionResult Delete(int InvoiceID)
        {
            context = new DALContext();
            context.Invoices.Delete(p => p.Id == InvoiceID);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        public ActionResult Delete(int OrderID)
        {
            context = new DALContext();
            context.Orders.Delete(p => p.Id == OrderID);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 20
0
        public ActionResult DeleteOrderProduct(int OrderProductID)
        {
            context = new DALContext();
            context.OrdersProducts.Delete(p => p.Id == OrderProductID);
            context.SaveChanges();

            return(Content("Item Excluído com Sucesso!"));
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Return 1: New User has succeeded to register.
 /// Return 0: Has exception
 /// Return 2: UserName or Email is already in system.
 /// </summary>
 /// z
 /// <param name="user"></param>
 /// <returns></returns>
 public int Register(User user)
 {
     if (CheckUser(user))
     {
         try
         {
             context.Users.Create(user);
             context.SaveChanges();
             return(0);
         }
         catch (Exception exception)
         {
             _logService.LogError("Function Register: {0}", exception);
             return(2);
         }
     }
     return(1);
 }
Ejemplo n.º 22
0
        public ActionResult IncluirCondicaoPagamento(Model.Entities.PaymentTerm PaymentTerm, int CustomerID)
        {
            try
            {
                context = new DALContext();

                context.PaymentTerms.Create(PaymentTerm);

                var Customer = context.Customers.Find(p => p.Id == CustomerID);
                context.SaveChanges();

                Customer.PaymentTermId = PaymentTerm.Id;
                context.Customers.Update(Customer);
                context.SaveChanges();

                return(Content(String.Format("{0}", PaymentTerm.Id)));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 23
0
        public ActionResult EnviarParaFonecedor(int OrderID)
        {
            context = new DALContext();

            PurchaseOrder purchaseOrder = context.PurchaseOrders.Find(p => p.Id == OrderID);

            purchaseOrder.Status = "PEDIDO_PENDENTE";
            context.PurchaseOrders.Update(purchaseOrder);

            context.SaveChanges();

            return(RedirectToAction("Recebimento"));
        }
Ejemplo n.º 24
0
        // HINT: For step 2 you'll need to add a new parameter so you can set a value for the
        // QueryResults collection in Query
        public Query SaveQuery(string queryText, DateTime time)
        {
            var q =
                new Query()
            {
                QueryText = queryText,
                Time      = time
            };

            context.Queries.Create(q);
            context.SaveChanges();
            return(q);
        }
Ejemplo n.º 25
0
        public JsonResult GetAddressByCep(string cep)
        {
            var  CEP        = new DAL.CEP.Objects.CEP();
            City objCityCEP = new City();

            try
            {
                objCityCEP            = CEP.GetCityByCEP(cep);
                objCityCEP.CEP        = Utility.Serialization.Deserialize <Utility.CEP>(Utility.Utilities.GetXmlAddressByCEP(cep));
                objCityCEP.Name       = objCityCEP.CEP.Cidade.ToUpper();
                objCityCEP.CEP.Bairro = objCityCEP.CEP.Bairro.ToUpper();

                context = new DALContext();

                bool cityExists = context.Cities.Find(p => p.IBGECode == objCityCEP.IBGECode) == null ? false : true;

                if (!cityExists)
                {
                    var objCity = new City()
                    {
                        Name       = objCityCEP.Name,
                        CEPInicial = objCityCEP.CEPInicial,
                        CEPFinal   = objCityCEP.CEPFinal,
                        IBGECode   = objCityCEP.IBGECode,
                        StateId    = context.States.Find(p => p.UF.Trim().ToUpper() == objCityCEP.CEP.UF.Trim().ToUpper()).Id,
                        CEP        = objCityCEP.CEP
                    };

                    context.Cities.Create(objCity);
                    context.SaveChanges();

                    var ListaCidades = context.Cities.All().OrderBy(p => p.Name).ToList();

                    return(Json(new { Cidade = objCity, ListaCidades = ListaCidades }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var objCity = context.Cities.Find(p => p.IBGECode == objCityCEP.IBGECode);
                    objCity.CEP = objCityCEP.CEP;

                    var ListaCidades = context.Cities.All().OrderBy(p => p.Name).ToList();

                    return(Json(new { Cidade = objCity, ListaCidades = ListaCidades }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
                //return Json(new { Cidade = "", ListaCidades = "" }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 26
0
        public ActionResult Delete(int OrderID)
        {
            context = new DALContext();
            //context.PurchaseOrders.Delete(p => p.Id == OrderID);

            PurchaseOrder purchaseOrder = context.PurchaseOrders.Find(p => p.Id == OrderID);

            purchaseOrder.Status = "CANCELADO";
            context.PurchaseOrders.Update(purchaseOrder);

            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 27
0
        // HINT: For step 2 you'll need to add a new parameter so you can set a value for the
        // QueryResults collection in Query
        public Query SaveQuery(string queryText, DateTime time, ICollection <SearchResult> searchResults)
        {
            var q =
                new Query()
            {
                QueryText     = queryText,
                Time          = time,
                SearchResults = searchResults
            };

            context.Queries.Create(q);
            context.SaveChanges();
            return(q);
        }
Ejemplo n.º 28
0
        public ActionResult IncluirContato(Model.Entities.Contact Contact, int CustomerID)
        {
            try
            {
                context = new DALContext();

                context.Contacts.Create(Contact);
                context.SaveChanges();

                return(Content(String.Format("{0}", Contact.Id)));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 29
0
        public ActionResult ClienteDelete(int?ClientID)
        {
            context = new DALContext();

            try
            {
                var retorno = context.Customers.Delete(p => p.Id == ClientID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            context.SaveChanges();

            ViewBag.Message = "Cliente excluído com sucesso.";

            return(RedirectToAction("Clientes"));
        }
Ejemplo n.º 30
0
        public ActionResult ConfirmarProposta(int OrderID)
        {
            context = new DALContext();
            Order retorno = new Order();

            try
            {
                retorno           = context.Orders.Find(p => p.Id == OrderID);
                retorno.Validated = true;
                context.SaveChanges();

                return(Content(String.Format("Proposta  número {0} atualizada com sucesso!", OrderID)));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }