Example #1
0
        // GET: Providers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CSales.Database.Models.Provider provider = this.db.Provider.Find(id);
            if (provider == null)
            {
                return(HttpNotFound());
            }

            var prov = new DetailsProviderViewModel
            {
                Contact           = provider.Contact,
                Id                = provider.Id,
                IdBusinessName    = provider.BusinessName.Id,
                IsActive          = provider.IsActive,
                IsForeignProvider = provider.IsForeignProvider,
                Name              = provider.Name,
                Telephones        = this.db.TelephoneProvider.Where(t => t.IdPRV == provider.Id),
                Addresses         = this.db.AddressProvider.Where(a => a.IdPRV == provider.Id),
                CitiesDistricts   = this.db.CityProvider.Where(cd => cd.IdProv == provider.Id)
            };

            return(View(prov));
        }
Example #2
0
        public ActionResult Create(CreateProviderViewModel provider)
        {
            if (ModelState.IsValid)
            {
                var P = new CSales.Database.Models.Provider
                {
                    Contact           = provider.Contact,
                    IsActive          = provider.IsActive,
                    Name              = provider.Name,
                    IsForeignProvider = provider.IsForeignProvider,
                };

                this.db.Database.ExecuteSqlCommand(@"INSERT INTO PROVIDER(NAME, ISACTIVE, CONTACT, ISFOREIGNPROVIDER, BUSINESSNAME, CREATEDDATE) values ({0},{1},{2},{3},{4},{5})", provider.Name, provider.IsActive, provider.Contact, provider.IsForeignProvider, provider.IdBusinessName, DateTime.Now);

                var newProv = this.db.Provider.OrderByDescending(x => x.Id).FirstOrDefault();

                for (int i = 0; i < provider.Addresses.Count(); i++)
                {
                    this.db.Database.ExecuteSqlCommand(@"INSERT INTO APRV(ADDRESSNAME,DESCRIPTION,IDPRV) values ({0},{1},{2})", provider.Addresses.ElementAt(i), "Descripcion default", newProv.Id);
                }

                for (int i = 0; i < provider.Telephones.Count(); i++)
                {
                    this.db.Database.ExecuteSqlCommand(@"INSERT INTO TELPROV(NUMBER,DESCRIPTION,IDPRV) values ({0},{1},{2})", provider.Telephones.ElementAt(i), "Descripcion default", newProv.Id);
                }

                var cCorriente = new CurrentAccountProvider
                {
                    CreatedDate = DateTime.Now,
                    IdProvider  = newProv.Id,
                    TotalDebt   = 0
                };

                this.db.CurrentAcountProvider.Add(cCorriente);
                this.db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            this.ViewBag.IdBusinessName = new SelectList(db.BusinessName, "Id", "Name", provider.IdBusinessName);
            return(View(provider));
        }