Пример #1
0
        public ActionResult Create([Bind(Include = "CodeP,NomP")] Projet projet)
        {
            if (ModelState.IsValid)
            {
                db.Projets.Add(projet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(projet));
        }
        public ActionResult Create([Bind(Include = "NumDep,NomDep,Lieu")] Departement departement)
        {
            if (ModelState.IsValid)
            {
                db.Departements.Add(departement);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(departement));
        }
        public ActionResult Create([Bind(Include = "UserID,UserName,UserEmail,UserPassowrd,UserAddress,UserBalance,UserType")] UserInfo userInfo)
        {
            if (ModelState.IsValid)
            {
                db.UserInfoes.Add(userInfo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userInfo));
        }
 public ActionResult Edit([Bind(Include = "Cedula,SiglaExam,Descripcion")] Aplica_Transacciones aplica_Transacciones)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aplica_Transacciones).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Cedula    = new SelectList(db.Profesor_Transacciones, "Cedula", "Cedula", aplica_Transacciones.Cedula);
     ViewBag.SiglaExam = new SelectList(db.Examen_Transacciones, "SiglaExam", "SiglaExam", aplica_Transacciones.SiglaExam);
     return(View(aplica_Transacciones));
 }
        public ActionResult Create([Bind(Include = "Matr,NomE,Post,DateEmb,Sup,Salaire,Comm,NumDep")] Employe employe)
        {
            if (ModelState.IsValid)
            {
                db.Employes.Add(employe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.NumDep = new SelectList(db.Departements, "NumDep", "NomDep", employe.NumDep);
            return(View(employe));
        }
        public ActionResult Create([Bind(Include = "Matr,CodeP,Fonction")] Participation participation)
        {
            if (ModelState.IsValid)
            {
                db.Participations.Add(participation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Matr  = new SelectList(db.Employes, "Matr", "NomE", participation.Matr);
            ViewBag.CodeP = new SelectList(db.Projets, "CodeP", "NomP", participation.CodeP);
            return(View(participation));
        }
Пример #7
0
        public void Delete(object obj)
        {
            if (obj is Author)
            {
                _context.Author.Remove((Author)obj);
            }
            if (obj is Post)
            {
                _context.Post.Remove((Post)obj);
            }

            _context.SaveChanges();
        }
Пример #8
0
        public void RegisterUser(RegisterUserRequest req)
        {
            string userId = UserIdFactory.GetUserId();

            db.User.Add(new User()
            {
                Id          = userId,
                LoginId     = req.LoginId,
                Name        = req.Name,
                MailAddress = req.MailAddress
            });

            db.SaveChanges();
        }
Пример #9
0
        private void Delete_client()
        {
            if (MessageBox.Show("Вы дейтсвительно хотите удалить запись?", "Удаление",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
            {
                using (DataBaseEntities db = new DataBaseEntities())
                {
                    int ID     = (int)dgv_client[0, dgv_client.SelectedRows[0].Index].Value;
                    var client = db.Client.FirstOrDefault(c => c.ID == ID);

                    if (client.VisitInfo.Count > 0)
                    {
                        MessageBox.Show("Невозможно удалить запись, так как есть данные о посещении.");
                    }
                    else
                    {
                        db.Client.Remove(client);

                        if (client.TagOfClient.Select(t => t.Tag).ToList().Count > 0)
                        {
                            foreach (var tag in client.TagOfClient.Select(t => t.Tag).ToList())
                            {
                                db.Tag.Remove(tag);
                            }
                        }

                        db.SaveChanges();
                        UpdateData();
                    }
                }
            }
        }
Пример #10
0
 void IDeviceService.Delete(int DeviceId)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Device oldDevice = context.Devices.Where(i => i.DeviceID == DeviceId).First();
         context.DeleteObject(oldDevice);
         context.SaveChanges();
     }
 }
Пример #11
0
 void IDeviceService.Update(Device Device)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Device oldDevice = context.Devices.Where(i => i.DeviceID == Device.DeviceID).First();
         oldDevice = Device;
         context.SaveChanges();
     }
 }
Пример #12
0
 int IDeviceService.Add(Device Device)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         context.Devices.AddObject(Device);
         context.SaveChanges();
         return(Device.DeviceID);
     }
 }
Пример #13
0
 void IInvoiceService.Update(Invoice Invoice)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Invoice oldInvoice = context.Invoices.Where(i => i.InvoiceID == Invoice.InvoiceID).First();
         oldInvoice = Invoice;
         context.SaveChanges();
     }
 }
Пример #14
0
 void IOrderService.Delete(int OrderID)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Order oldOrder = context.Orders.Where(i => i.OrderID == OrderID).First();
         context.DeleteObject(oldOrder);
         context.SaveChanges();
     }
 }
Пример #15
0
 int IProductService.Add(Product Product)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         context.Products.AddObject(Product);
         context.SaveChanges();
         return(Product.ProductID);
     }
 }
Пример #16
0
 int IOrderService.Add(Order Order)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         context.Orders.AddObject(Order);
         context.SaveChanges();
         return(Order.OrderID);
     }
 }
Пример #17
0
 void IProductService.Delete(int ProductID)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Product oldProduct = context.Products.Where(i => i.ProductID == ProductID).First();
         context.DeleteObject(oldProduct);
         context.SaveChanges();
     }
 }
Пример #18
0
 void IOrderService.Update(Order Order)
 {
     using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
     {
         Order oldOrder = context.Orders.Where(i => i.OrderID == Order.OrderID).First();
         oldOrder = Order;
         context.SaveChanges();
     }
 }
Пример #19
0
        public void SaveText(RegisterTextRequest req)
        {
            var target = db.Text.FirstOrDefault(x => x.UserId == req.UserId);

            target.Title       = req.Title;
            target.Description = req.Description;
            target.Profile_1   = req.Profile_1;

            db.SaveChanges();
        }
Пример #20
0
        public ActionResult Create([Bind(Include = "Code,ItemName,ItemDescription,ItemPrice,Department,logo")] Item item, HttpPostedFileBase imgFile)
        {
            string path = "";

            if (imgFile.FileName.Length > 0)
            {
                path = "~/images/" + Path.GetFileName(imgFile.FileName);
                imgFile.SaveAs(Server.MapPath(path));
            }

            item.logo = path;



            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Пример #21
0
        void IProductService.Update(Product Product)
        {
            using (var context = new DataBaseEntities(DBManager.EntityConnectionString))
            {
                Product oldProduct = context.Products.Where(i => i.ProductID == Product.ProductID).First();

                oldProduct.isDiscontinued = Product.isDiscontinued;
                oldProduct.ProductCode    = Product.ProductCode;
                oldProduct.ProductGroup   = Product.ProductGroup;
                oldProduct.ProductName    = Product.ProductName;
                oldProduct.ProductPrice   = Product.ProductPrice;
                context.SaveChanges();
            }
        }
Пример #22
0
 void ICustomerService.Update(Customer Customer)
 {
     using (var context = new DataBaseEntities())
     {
         try
         {
             context.Customers.Attach(Customer);
             context.ObjectStateManager.ChangeObjectState(Customer, EntityState.Modified);
             context.SaveChanges();
         }
         catch (Exception)
         {
             throw new FaultException("Error updating customer id#" + Customer.CustomerID);
         }
     }
 }
Пример #23
0
        public async Task <IHttpActionResult> ProfilePortraitChange([FromBody] TD_Portrait model)
        {
            DataBaseEntities db = new DataBaseEntities();
            var UserId          = User.Identity.GetUserId();
            var user            = db.AspNetUsers.Single(u => u.Id == UserId);

            user.Portrait = model.image;
            db.SaveChanges();
            user = db.AspNetUsers.Single(u => u.Id == UserId);
            return(Json(new
            {
                Code = 10000,
                Detail = new
                {
                    Portrait = user.Portrait
                }
            }));
        }
Пример #24
0
        int ICustomerService.Add(Customer Customer)
        {
            using (var context = new DataBaseEntities())
            {
                try
                {
                    context.Customers.AddObject(Customer);
                    context.ObjectStateManager.ChangeObjectState(Customer, EntityState.Added);
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    throw new FaultException("Could not create Customer");
                }

                return(Customer.CustomerID);
            }
        }
Пример #25
0
        void ICustomerService.Delete(int CustomerID)
        {
            using (var context = new DataBaseEntities())
            {
                try
                {
                    Customer cust = context.Customers
                                    .Where(c => c.CustomerID == CustomerID)
                                    .FirstOrDefault();

                    context.DeleteObject(cust);
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    throw new FaultException("Error deleting customer id#" + CustomerID);
                }
            }
        }
Пример #26
0
        private void deleteTag_Click(object sender, EventArgs e)
        {
            if (listTags.SelectedItems.Count > 0)
            {
                using (DataBaseEntities db = new DataBaseEntities())
                {
                    Tag         tag         = (Tag)listTags.SelectedItems[0].Tag;
                    TagOfClient tagOfClient = db.TagOfClient.FirstOrDefault(t => t.TagID == tag.ID && t.ClientID == client.ID);

                    if (db.TagOfClient.ToList().Exists(t => t.ID == tagOfClient.ID &&
                                                       t.ClientID == tagOfClient.ClientID))
                    {
                        listTags.Items.Remove(listTags.SelectedItems[0]);
                        db.TagOfClient.Remove(tagOfClient);
                    }

                    db.SaveChanges();
                }
            }
        }
Пример #27
0
        private void Save()
        {
            var results = new List <ValidationResult>();
            var context = new ValidationContext(bindingSourceClient[0]);

            if (!Validator.TryValidateObject(client, context, results, true))
            {
                foreach (var error in results)
                {
                    MessageBox.Show(error.ErrorMessage, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (MessageBox.Show("Сохранить?", "Сохранение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                using (DataBaseEntities db = new DataBaseEntities())
                {
                    if (!db.Client.ToList().Exists(c => c.ID == client.ID))
                    {
                        client.RegistrationDate = DateTime.Now;
                        db.Client.Add((ModelDB.Client)bindingSourceClient[0]);
                    }
                    var tagOfClients = db.TagOfClient.ToList();
                    foreach (ListViewItem item in listTags.Items)
                    {
                        Tag         tag         = (Tag)item.Tag;
                        TagOfClient tagOfClient = new TagOfClient {
                            ClientID = client.ID, TagID = tag.ID
                        };

                        if (tagOfClients.Exists(t => t.TagID == tagOfClient.TagID && t.ClientID == client.ID) == false)
                        {
                            db.Tag.Add(tag);
                            db.TagOfClient.Add(tagOfClient);
                        }
                    }
                    db.SaveChanges();
                }
            }
        }
Пример #28
0
        /// <summary>
        /// 判断该电话号码和验证码是否合法
        /// </summary>
        /// <param name="Mobile">手机号码</param>
        /// <param name="Code">验证码</param>
        /// <param name="NeedDelete">是否需要删除</param>
        /// <returns></returns>
        public static bool VerifyMobileCode(string Mobile, int Code, bool NeedDelete)
        {
            if (UtilityHelper.ConstVar.testAccount.Contains(Mobile))
            {
                return(true);
            }
            DataBaseEntities db = new DataBaseEntities();
            DateTime         dt = UtilityHelper.getNow().AddMinutes(-5); //延迟5分钟

            if (db.cm_SMS_Verify.Any(u => (u.Mobile == Mobile && u.Code == Code && u.CreateDate > dt)))
            {
                if (NeedDelete)
                {
                    var obj = db.cm_SMS_Verify.Where(u => u.Mobile == Mobile);
                    db.cm_SMS_Verify.RemoveRange(obj);
                    db.SaveChanges();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public ActionResult Register(RegisterViewModel model)
        {
            _currentUser = (User)Session["CurrentUser"];
            if (_currentUser != null)
            {
                return(RedirectToAction("Index"));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _currentUser              = new User();
            _currentUser.Username     = model.Username;
            _currentUser.Password     = model.Password;
            _currentUser.FirstName    = model.FirstName;
            _currentUser.LastName     = model.LastName;
            _currentUser.RegisterDate = System.DateTime.Now;
            db.Users.Add(_currentUser);
            db.SaveChanges();
            Session.Add("CurrentUser", _currentUser);
            return(RedirectToAction("Index"));
        }
Пример #30
0
        public async Task <IHttpActionResult> VcodeSendSMS(string m)
        {
            if (UtilityHelper.ConstVar.testAccount.Any(u => u == m))
            {
                return(Json(new
                {
                    Code = 10000,
                    Detail = new { }
                }));
            }
            if (!UtilityHelper.IsMobilePhone(m))
            {
                return(Json(new
                {
                    Code = 1,
                    Message = "手机格式不正确"
                }));
            }

            Random ran     = new Random();
            int    RandKey = ran.Next(1000, 9999);

            try
            {
                string mobile             = m,
                       message            = "验证码:" + RandKey.ToString() + " ,两分钟内有效【活动邮】",
                       username           = ConfigurationManager.AppSettings["SMSUsername"],
                       password           = ConfigurationManager.AppSettings["SMSKey"],
                       url                = ConfigurationManager.AppSettings["SMSUrl"];
                byte[]         byteArray  = Encoding.UTF8.GetBytes("mobile=" + mobile + "&message=" + message);
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
                string         auth       = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(username + ":" + password));
                webRequest.Headers.Add("Authorization", auth);
                webRequest.Method        = "POST";
                webRequest.ContentType   = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;

                Stream newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                StreamReader    php      = new StreamReader(response.GetResponseStream(), Encoding.Default);
                string          Message  = php.ReadToEnd();
            }
            catch
            {
                return(Json(new
                {
                    Code = 1,
                    Message = "验证码服务器有误"
                }));
            }

            DataBaseEntities db = new DataBaseEntities();

            var verify = new cm_SMS_Verify
            {
                Id         = Guid.NewGuid().ToString(),
                Code       = RandKey,
                CreateDate = DateTime.Now,
                Mobile     = m
            };

            db.cm_SMS_Verify.Add(verify);
            db.SaveChanges();

            return(Json(new
            {
                Code = 10000,
                Detail = new
                {
                }
            }));
        }