public ActionResult Create([Bind(Include = "VendedorID,Codigo,NombreVendedor,Celular,Email,EmpresaID")] Vendedor vendedor)
        {
            if (ModelState.IsValid)
            {
                bool hasErrors = false;
                DbContextTransaction Transaction = null;

                try
                {
                    Transaction        = db.Database.BeginTransaction();
                    vendedor.EmpresaID = ApplicationContext.CurrentUser.EmpresaID;
                    db.Vendedores.Add(vendedor);
                    db.SaveChanges();

                    Transaction.Commit();
                }
                catch (Exception eX)
                {
                    if (Transaction != null)
                    {
                        Transaction.Rollback();
                    }

                    ModelState.AddModelError("", eX.Message);
                    hasErrors = true;
                }
                if (!hasErrors)
                {
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.EmpresaID = new SelectList(db.Empresas, "EmpresaID", "Nombre", vendedor.EmpresaID);
            return(View(vendedor));
        }
 public IActionResult CreateFilial(IFormCollection collection)
 {
     _context.Filials.Add(new Filial {
         Name = collection["Name"]
     });
     _context.SaveChanges();
     return(Redirect("/Customer/Filial"));
 }
Example #3
0
        private void BuyerAddToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            var form = new CustomerForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                db.Customers.Add(form.Customer);
                db.SaveChanges();
            }
        }
Example #4
0
        public ActionResult Create([Bind(Include = "CiudadID,Ciudad")] Ciudades ciudades)
        {
            if (ModelState.IsValid)
            {
                db.Ciudades.Add(ciudades);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ciudades));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "VolunteerID,OccurenceID,VolunteerType")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                db.Volunteers.Add(volunteer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(volunteer));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "EmployeeID,Forename,Surname,DateOfBirth")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Example #7
0
        public ActionResult Create([Bind(Include = "TeacherID")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                db.Teachers.Add(teacher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(teacher));
        }
Example #8
0
        public ActionResult Create([Bind(Include = "CourseID,CourseName,CourseCategory,CourseDate")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(course));
        }
Example #9
0
        public ActionResult Create([Bind(Include = "DonationID,DonorID,DonationArea,DonationAmount")] Donation donation)
        {
            if (ModelState.IsValid)
            {
                db.Donations.Add(donation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(donation));
        }
Example #10
0
        public ActionResult Create([Bind(Include = "Id,Name,Email,PhoneNumber")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Example #11
0
        public ActionResult Create([Bind(Include = "SectorEconomicoID,SectorEconomico")] SectoresEconomicos sectoresEconomicos)
        {
            if (ModelState.IsValid)
            {
                db.SectoresEconomicos.Add(sectoresEconomicos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sectoresEconomicos));
        }
Example #12
0
        public ActionResult Create([Bind(Include = "OccurenceID,OccurenceName,OccurenceCategory,OccurenceDate")] Occurence occurence)
        {
            if (ModelState.IsValid)
            {
                db.Occurences.Add(occurence);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(occurence));
        }
Example #13
0
        public ActionResult Create([Bind(Include = "AffiliationID,ConstituentID,EmployerName")] Affiliation affiliation)
        {
            if (ModelState.IsValid)
            {
                db.Affiliations.Add(affiliation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(affiliation));
        }
Example #14
0
        public ActionResult Create([Bind(Include = "ClientID,Forename,Surname,DateOfBirth,AddressDetails")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
Example #15
0
        public ActionResult Create([Bind(Include = "ConstituentID,IsPerson,FirstName,LastName,Address,City,State,ZipCode,Country,Email,PhoneNumber,ReferralMethod,ActiveSince,AgeRange,Notes")] Constituent constituent)
        {
            if (ModelState.IsValid)
            {
                db.Constituents.Add(constituent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(constituent));
        }
Example #16
0
        public ActionResult Create([Bind(Include = "ArtistID,ArtistCategory")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
Example #17
0
        public ActionResult Create([Bind(Include = "ContactoID,ClienteID,Nombre,Cargo,Telefono,Celular,Email")] Contactos contactos)
        {
            if (ModelState.IsValid)
            {
                db.Contactos.Add(contactos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClienteID = new SelectList(db.Clientes, "ClienteID", "Nombre", contactos.ClienteID);
            return(View(contactos));
        }
Example #18
0
        public ActionResult Create([Bind(Include = "Id,Date,Description,ContactId")] Annotation annotation)
        {
            if (ModelState.IsValid)
            {
                db.Annotations.Add(annotation);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(RedirectToAction("Index", "Contacts"));
            }

            return(View(annotation));
        }
        public ActionResult Create([Bind(Include = "PeticionID,FechaRegistro,Titulo,Descripcion,TipoPeticion,EmpresaID,UserID")] Peticion peticion)
        {
            if (ModelState.IsValid)
            {
                peticion.UserID    = ApplicationContext.CurrentUser.Id;
                peticion.EmpresaID = ApplicationContext.CurrentUser.EmpresaID;
                db.Peticions.Add(peticion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(peticion));
        }
Example #20
0
        public IActionResult CreateFilial(IFormCollection collection)
        {
            var NewFilial = new Filial {
                Name = collection["Name"]
            };

            if (!TryValidateModel(NewFilial))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            _context.Filials.Add(NewFilial);
            _context.SaveChanges();
            return(Redirect("/Customer/Filial"));
        }
Example #21
0
        public IActionResult Create(IFormCollection collection)
        {
            int filialId;

            int.TryParse(collection["Filial"], out filialId);
            int customerId;

            int.TryParse(collection["CustomerId"], out customerId);

            _context.CustomerAccounts.Add(new CustomerAccount {
                CustomerId = customerId, FilialId = filialId
            });
            _context.SaveChanges();
            return(Redirect("/Customer/Details?id=" + customerId));
        }
Example #22
0
        public JsonResult SchoolAdd([FromBody] Schools schools)
        {
            _crmcontext.Schools.Add(schools);
            int i = _crmcontext.SaveChanges();

            if (i > 0)//当集合的成员大于0时候,说明登录成功
            {
                //return RedirectToAction("Index", "Users");//跳转到主页面
                return(new JsonResult(i));
            }
            else
            {
                return(new JsonResult(i));
            }
        }
Example #23
0
 public string create(AccountDto accountDto)
 {
     try
     {
         Account accountNew = mapper.Map <AccountDto, Account>(accountDto);
         accountNew.CreateDate = DateTime.Now;
         _context.Account.Add(accountNew);
         _context.SaveChanges();
         return("0");
     }
     catch (Exception)
     {
         return("1");
     }
 }
        public ActionResult Create([Bind(Include = "ClienteID,Nombre,RazonSocial,Nit,RepresentanteLegal,SectorEconomicoID,CiudadID,Direccion,Telefono,Celular,Email,SitioWeb,EmpresaID,VendedorID")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                cliente.EmpresaID = ApplicationContext.CurrentUser.EmpresaID;
                db.Clientes.Add(cliente);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CiudadID          = new SelectList(db.Ciudades.OrderBy(c => c.Ciudad), "CiudadID", "Ciudad", cliente.CiudadID);
            ViewBag.SectorEconomicoID = new SelectList(db.SectoresEconomicos.OrderBy(s => s.SectorEconomico), "SectorEconomicoID", "SectorEconomico", cliente.SectorEconomicoID);
            ViewBag.VendedorID        = new SelectList(db.Vendedores.Where(c => c.EmpresaID.Equals(ApplicationContext.CurrentUser.EmpresaID))
                                                       .OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor");
            return(View(cliente));
        }
Example #25
0
        /// <summary>
        /// Добавляет событие
        /// </summary>
        public CallEvent AddCallEvent(CallEvent callEvent)
        {
            db.CallEvents.Add(callEvent);
            db.SaveChanges();

            return(callEvent);
        }
Example #26
0
        public string create(BankDto bankDto)
        {
            try {
                Bank bankNew = mapper.Map <BankDto, Bank>(bankDto);
                bankNew.Id         = Guid.NewGuid().ToString();
                bankNew.CreateDate = DateTime.Now;

                _context.Bank.Add(bankNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
        public ActionResult CopyTbl()
        {
            string strsql  = "select * into [dbo].[UsrStat" + DateTime.Now.ToString("ddMMyyyyhhmm") + "] from [dbo].[UsrStat]";
            string strsql1 = "select * into [dbo].[CtrlActStat" + DateTime.Now.ToString("ddMMyyyyhhmm") + "] from [dbo].[CtrlActStat]";
            string sqlstr2 = "delete from [dbo].[UsrStat]";
            string sqlstr3 = "delete from [dbo].[CtrlActStat]";

//
            using (var dbContextTransaction = context.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                try
                {
                    context.Database.ExecuteSqlCommand(strsql);
                    context.Database.ExecuteSqlCommand(sqlstr2);
                    context.Database.ExecuteSqlCommand(strsql1);
                    context.Database.ExecuteSqlCommand(sqlstr3);

                    context.SaveChanges();

                    dbContextTransaction.Commit();
                    return(Json(new { success = true }));
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                    List <string> errors = new List <string>();
                    errors.Add("Error " + strsql + " or " + strsql1);
                    return(Json(new { success = false, errors = errors }));
                }
            }
        }
Example #28
0
        public void SporcuTakiminiGuncelle(Sporcu sporcu, int takimid)
        {
            using (CRMContext _db = new CRMContext())
            {
                //Sporcu eskiSporcu = _db.Sporcu.Where(x => x.ID == sporcu.ID).FirstOrDefault();

                //var query = (from takim in _db.Takim
                // join sporcu1 in _db.Sporcu on takim.ID equals sporcu1.ID
                // where takim.TakimSporculari.Any(x => x.ID == sporcu.ID) == true
                // select takim.ID).ToList();
                //foreach (Takim item in query)
                //{
                //     item.= takimid;
                //}

                Sporcu eskiSporcu = _db.Sporcu.Where(x => x.ID == sporcu.ID).FirstOrDefault();
                eskiSporcu.AktifMi = true;
                eskiSporcu.TakimID = takimid;
                _db.SaveChanges();
                //var query = from takim in _db.Takim
                //            join sporcu in _db.Sporcu on takim.ID equals sporcu.ID
                //            where takim.TakimSporculari.Any(x => x.ID == sporcuid) == true
                //            select sporcu.SporcuTakimlari.FirstOrDefault();
                //foreach (Takim stakim in query)
                //{
                //    stakim.ID = takimid;
                //}
                //return (from takim in _db.Takim
                //        join sporcu in _db.Sporcu on takim.ID equals sporcu.ID
                //        where takim.TakimSporculari.Any(x => x.ID == id) == true
                //        select takim.ID).ToList();
            }
        }
Example #29
0
        private void button2_Click(object sender, EventArgs e)
        {
            var id = dataGridView.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                var product = set.Find(id) as Product;
                if (product != null)
                {
                    var form = new ProductForm(product);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        product = form.Product;
                        db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Seller))
            {
                var seller = set.Find(id) as Seller;
                if (seller != null)
                {
                    var form = new SellerForm(seller);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        seller = form.Seller;
                        db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Customer))
            {
                var customer = set.Find(id) as Customer;
                if (customer != null)
                {
                    var form = new CustomerForm(customer);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        customer = form.Customer;
                        db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
        }
Example #30
0
        public string create(AccountDto tAccountDto)
        {
            try
            {
                Account tAccountNew = mapper.Map <AccountDto, Account>(tAccountDto);
                // tAccountNew.Username = Guid.NewGuid().ToString();
                tAccountNew.CreateDate = DateTime.Now;

                _context.Account.Add(tAccountNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }