コード例 #1
0
        public ActionResult AddExcerciseToPlan(CreatePlanViewModel cpVM)
        {
            cpVM.plan = int.Parse(Session["planID"].ToString());
            if (ModelState.IsValid)
            {
                using (var dbContext = new Model1())
                {
                    cpVM.exercisesInSession.ExercisesInSessionId = ExercisesInSession.GenerateId();
                    var sessions = dbContext.TrainingSessionsInPlan.Where(s => s.PlanId == cpVM.plan).ToList();
                    if (sessions.Count() != 0)
                    {
                        foreach (var session in sessions)
                        {
                            var tSession = dbContext.TrainingSession.FirstOrDefault(s => s.DayOfTraining == cpVM.day && s.SessionId == session.SessionId);
                            if (tSession != null)
                            {
                                cpVM.exercisesInSession.SessionId = tSession.SessionId;
                            }
                        }
                    }
                    else
                    {
                        var newTrainingSession = new TrainingSession
                        {
                            SessionId     = TrainingSession.GenerateId(),
                            DayOfTraining = cpVM.day
                        };
                        cpVM.exercisesInSession.SessionId = newTrainingSession.SessionId;
                        var newSessionInPlan = new TrainingSessionsInPlan
                        {
                            SessionId = newTrainingSession.SessionId,
                            PlanId    = cpVM.plan
                        };
                        dbContext.TrainingSessionsInPlan.Add(newSessionInPlan);
                        dbContext.TrainingSession.Add(newTrainingSession);
                    }

                    dbContext.ExercisesInSession.Add(cpVM.exercisesInSession);
                    dbContext.SaveChanges();
                }
            }
            return(RedirectToAction("EditPlan", "Trainer", new { planId = cpVM.plan }));
        }
コード例 #2
0
        public ActionResult Inscription(User user)
        {
            if (ModelState.IsValid)
            {
                user.Password = Crypto.HashPassword(user.Password);
                using (var model = new Model1())
                {
                    model.Users.Add(user);
                    model.SaveChanges();
                }
                FormsAuthentication.SetAuthCookie(user.Login.ToString(), true);

                // On stock l'Id de l'User en Session
                Session["userId"] = user.Id;

                return(Redirect("/Home/Contenu"));
            }
            return(View(user));
        }
コード例 #3
0
ファイル: EspecialBl.cs プロジェクト: 1000VIA/SRA
        public void ActualizarRegistro(Empresa oInstructor)
        {
            Model1 entity = new Model1();

            var Item = (from i in entity.Empresa
                        where i.NIT == oInstructor.NIT
                        select i).First();

            Item.NIT                = oInstructor.NIT;
            Item.Nombre             = oInstructor.Nombre;
            Item.Direccion          = oInstructor.Direccion;
            Item.Email              = oInstructor.Email;
            Item.Telefono           = oInstructor.Telefono;
            Item.Encargado          = oInstructor.Encargado;
            Item.Telefono_Encargado = oInstructor.Telefono_Encargado;
            Item.Tipo_Poblacion     = oInstructor.Tipo_Poblacion;
            Item.Estado             = true;
            entity.SaveChanges();
        }
コード例 #4
0
        private void GrabaAdiciona()
        {
            using (Model1 bd = new Model1())
            {
                Zk_Membresias dd = new Zk_Membresias();

                dd.DescripcionMembresias = TxtDescripcion.Text;
                dd.Ilimitado             = ChkLimitado.Checked;
                dd.MembresiaGrupo        = ChkGrupal.Checked;
                dd.EstadoAnulado         = ChkEstado.Checked;
                dd.InicioVigencia        = Convert.ToDateTime(DtpInicio.Text);
                dd.TerminoVigencia       = Convert.ToDateTime(Dtptermino.Text);
                dd.PeriodosID            = Convert.ToInt32(ctr_AyuPeriodos.Codigo);
                dd.Precio = Convert.ToDecimal(TxtPrecio.Text);

                bd.Zk_Membresias.Add(dd);
                bd.SaveChanges();
            }
        }
コード例 #5
0
        private void GrabaModifica()
        {
            using (Model1 bd = new Model1())
            {
                var dd = (from d in bd.Zk_Membresias
                          where d.ID == (vUserId)
                          select d).First();

                dd.DescripcionMembresias = TxtDescripcion.Text;
                dd.Ilimitado             = ChkLimitado.Checked;
                dd.MembresiaGrupo        = ChkGrupal.Checked;
                dd.EstadoAnulado         = ChkEstado.Checked;
                dd.InicioVigencia        = Convert.ToDateTime(DtpInicio.Text);
                dd.TerminoVigencia       = Convert.ToDateTime(Dtptermino.Text);
                dd.PeriodosID            = Convert.ToInt32(ctr_AyuPeriodos.Codigo);
                dd.Precio = Convert.ToDecimal(TxtPrecio.Text);
                bd.SaveChanges();
            }
        }
コード例 #6
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Model1 ctx      = new Model1();
            int    avnumber = int.Parse(GridView1.SelectedRow.Cells[1].Text);
            string itemcode = GridView1.SelectedRow.Cells[2].Text;

            StoreBusinessLogic.EditAdjust(avnumber, itemcode, "Approved");
            lab_successful.Text = "Change Successful";
            AdjustmentVoucher A = ctx.AdjustmentVouchers.Where(x => x.AVnumber == avnumber).First();

            A.ABName = Session["sign"].ToString();
            User u = ctx.Users.Where(x => x.UserName == A.ABName).First();

            A.ApproveBy = u.UserID;
            ctx.SaveChanges();
            btn_Notification.Enabled = true;
            Session["CRName"]        = A.CRName;
            Session["content"]       = Session["content"].ToString() + itemcode.ToString() + ",";
        }
コード例 #7
0
 private void Button_Click_7(object sender, RoutedEventArgs e)
 {
     try
     {
         var newAcct = exceldata.ItemsSource as IEnumerable <Account>;
         if (newAcct != null)
         {
             using (var contx = new Model1())
             {
                 foreach (var i in newAcct)
                 {
                     contx.Accounts.Add(i);
                 }
                 try
                 {
                     contx.SaveChanges();
                 }
                 catch (DbEntityValidationException ex)
                 {
                     foreach (var eve in ex.EntityValidationErrors)
                     {
                         MessageBox.Show("Entity of type " + eve.Entry.Entity.GetType().Name + " in state " + eve.Entry.State.ToString() + " has the following validation errors:");
                         foreach (var ve in eve.ValidationErrors)
                         {
                             MessageBox.Show("- Property: " + ve.PropertyName + ", Value: " + eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName) + ", Error: " + ve.ErrorMessage);
                         }
                     }
                     throw;
                 }
             }
             MessageBox.Show("Inserted");
         }
         else
         {
             MessageBox.Show("Fail !!!!!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Message");
     }
 }
コード例 #8
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                WithDraw Sperm          = new WithDraw();
                var      itemInfo       = db.Items.Where(r => r.Name == (string)comboBox1.SelectedItem).SingleOrDefault();
                var      supplierInfo   = db.Suppliers.Where(r => r.Name == (string)comboBox2.SelectedItem).SingleOrDefault();
                var      storeInfo      = db.WareHouses.Where(r => r.Name == (string)comboBox3.SelectedItem).SingleOrDefault();
                var      Customers      = db.Customers.Where(r => r.Name == (string)CBCust.SelectedItem).SingleOrDefault();
                var      wareHouseItems = db.WareHouseItems.Where(r => r.IdItem == itemInfo.ID).SingleOrDefault();
                if (string.IsNullOrWhiteSpace(TBQuantity.Text) || string.IsNullOrWhiteSpace(TBPermitNUM.Text))
                {
                    MessageBox.Show("Please Complete empty Field");
                }

                else if (Convert.ToInt32(TBQuantity.Text) > wareHouseItems.Quantity)
                {
                    MessageBox.Show("this Quantity Greater than item Quantity");
                }
                else
                {
                    Sperm.IdItem      = itemInfo.ID;
                    Sperm.IdSupplier  = supplierInfo.Id;
                    Sperm.IdWareHouse = storeInfo.Id;
                    Sperm.IdCustomer  = Customers.IdCustomers;

                    Sperm.LicenseData = LicenseDate.Value;
                    Sperm.Quantity    = Convert.ToInt32(TBQuantity.Text);
                    Sperm.LicenseNum  = Convert.ToInt32(TBPermitNUM.Text);

                    db.WithDraws.Add(Sperm);
                    db.SaveChanges();

                    MessageBox.Show("Done");
                    this.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid Field");
            }
        }
コード例 #9
0
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            if (waste_code != null)
            {
                using (var db = new Model1())
                {
                    var to_modify = (from p in db.D_VerWasteCode
                                     where p.id == waste_code.id
                                     select p).Single();

                    to_modify.code           = tbcode.Text;
                    to_modify.MachineNo      = tbMachineNo.Text;
                    to_modify.errType        = tbErrType.Text;
                    to_modify.ProcessType    = tbProcessType.Text;
                    to_modify.ProductionDate = DateTime.Parse(tbProductionTime.Text);
                    to_modify.workUnit       = tbWorkUnit.Text;
                    to_modify.Note           = tbNote.Text;
                    to_modify.CheckerNo      = tbChecker.Text;
                    to_modify.CheckDate      = DateTime.Parse(tbCheckTime.Text);
                    db.SaveChanges();
                }
            }
            else
            {
                using (var db = new Model1())
                {
                    D_VerWasteCode to_add = new D_VerWasteCode();

                    to_add.code           = tbcode.Text;
                    to_add.MachineNo      = tbMachineNo.Text;
                    to_add.errType        = tbErrType.Text;
                    to_add.ProcessType    = tbProcessType.Text;
                    to_add.ProductionDate = DateTime.Parse(tbProductionTime.Text);
                    to_add.workUnit       = tbWorkUnit.Text;
                    to_add.Note           = tbNote.Text;
                    to_add.CheckerNo      = tbChecker.Text;
                    to_add.CheckDate      = DateTime.Parse(tbCheckTime.Text);
                    db.D_VerWasteCode.Add(to_add);
                    db.SaveChanges();
                }
            }
        }
コード例 #10
0
        public void ProcessRequest(HttpContext context)
        {
            var id = int.Parse(context.Request["id"]);

            using (Model1 entities1 = new Model1())
            {
                var rows = entities1.JDJS_PDMS_Staff_Table.Where(r => r.ParentID == id);
                if (rows.Count() > 0)
                {
                    context.Response.Write("请先删除所属子节点");
                }
                else
                {
                    var row = entities1.JDJS_PDMS_Staff_Table.Where(r => r.ID == id).First();
                    entities1.JDJS_PDMS_Staff_Table.Remove(row);
                    entities1.SaveChanges();
                    context.Response.Write("ok");
                }
            }
        }
コード例 #11
0
 public void SaveForm()
 {
     if (CanSaveForm())
     {
         using (var ctx = new Model1())
         {
             form.keyColumnPairs = keyColumnPairs.ToList();
             ctx.Forms.Add(form);
             ctx.SaveChanges();
         }
         form           = new Form();
         keyColumnPairs = new ObservableCollection <KeyColumnPair>();
         RaisePropertyChanged("keyColumnPairs");
         RaisePropertyChanged("IsPairsListVisible");
         keyColumnPairs.CollectionChanged += (s, e) => SaveFormCommand.RaiseCanExecuteChanged();
         addedPairsMessageVisible          = "Collapsed";
         RaisePropertyChanged("addedPairsMessageVisible");
         MessengerInstance.Send(new ItemAddedMessage());
     }
 }
コード例 #12
0
        public void EditImageResource(object sender, EventArgs e)
        {
            FileUpload fileUpload = (FileUpload)Page.FindControlRecursive("EditImageResourceFile");


            if (fileUpload.HasFile)
            {
                string fileName = Path.GetFileName(fileUpload.FileName);
                string path     = "~/Subjects/" + subjectID + "/Images/";
                fileUpload.SaveAs(Server.MapPath(path) + fileName);

                Model1    _db = new Model1();
                int       id  = int.Parse(ViewState["ResID"].ToString());
                resources res = (from resources in _db.resources where resources.ResourceID == id select resources).FirstOrDefault();

                res.ResourcePath = fileName;
                _db.SaveChanges();
                Refresh();
            }
        }
コード例 #13
0
        public static void delete_exercise(int exercise_id)
        {
            var db = new Model1();
            var ex = new Exercises();

            ex = db.Exercises.Where(m => m.id == exercise_id).First();
            foreach (var ex_train in db.Exercises_trainings.Where(m => m.id_exercise == ex.id))
            {
                foreach (var set in db.Series.Where(m => m.Exercises_trainings.id == ex_train.id))
                {
                    db.Series.Attach(set);
                    db.Series.Remove(set);
                }
                db.Exercises_trainings.Attach(ex_train);
                db.Exercises_trainings.Remove(ex_train);
            }
            db.Exercises.Attach(ex);
            db.Exercises.Remove(ex);
            db.SaveChanges();
        }
コード例 #14
0
        public ActionResult Create(FormCollection form)
        {
            post_comment pc = new post_comment();

            pc.user_Id      = User.Identity.GetUserId();
            pc.project_Id   = Int32.Parse(form["project_Id"]);
            pc.post_Id      = Int32.Parse(form["post_Id"]);
            pc.comment_desc = form["comment_desc"];

            try
            {
                db.post_comments.Add(pc);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotAcceptable));
            }
            return(RedirectToAction("Details" + "/" + form["post_Id"], "Post", new { area = "" }));
        }
コード例 #15
0
 public ActionResult EditOrCreate(Books Books)
 {
     using (Model1 db = new Model1())
     {
         if (Books.Id != 0)
         {
             var BooksTemp = db.Books.Where(a => a.Id == Books.Id).FirstOrDefault();
             BooksTemp.Title    = Books.Title;
             BooksTemp.Price    = Books.Price;
             BooksTemp.Pages    = Books.Pages;
             BooksTemp.AuthorId = Books.AuthorId;
         }
         else
         {
             db.Books.Add(Books);
         }
         db.SaveChanges();
     }
     return(RedirectToActionPermanent("Index", "Books"));
 }
コード例 #16
0
ファイル: BasicasBl.cs プロジェクト: 1000VIA/SRA
        public void ActualizarRegistroProgramacion(Competencias_Basicas oInstructor)
        {
            Model1 entity = new Model1();

            var Item = (from i in entity.Competencias_Basicas
                        where i.Id == oInstructor.Id
                        select i).First();

            Item.Fecha_Inicio = oInstructor.Fecha_Inicio;
            Item.Fecha_Final  = oInstructor.Fecha_Final;
            Item.Hora_Inicio  = oInstructor.Hora_Inicio;
            Item.Hora_Final   = oInstructor.Hora_Final;
            Item.Num_Ficha    = oInstructor.Num_Ficha;
            Item.Instructor   = oInstructor.Instructor;
            Item.Lugar        = oInstructor.Lugar;
            Item.Desc_Lugar   = oInstructor.Desc_Lugar;
            Item.Dias         = oInstructor.Dias;
            Item.Estado       = true;
            entity.SaveChanges();
        }
コード例 #17
0
 public ActionResult CreateOrEdit(Books book)
 {
     using (Model1 db = new Model1())
     {
         var editableBook = db.Books.Where(b => b.id == book.id).FirstOrDefault();
         if (editableBook == null)
         {
             db.Books.Add(book);
         }
         else
         {
             editableBook.title    = book.title;
             editableBook.price    = book.price;
             editableBook.pages    = book.pages;
             editableBook.authorId = book.authorId;
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Books"));
 }
コード例 #18
0
        public bool CreateTempSession(string temptitle, string tempdate, string tempdescr, int tempcode)
        {
            bool result = false;

            using (var context = new Model1())
            {
                var session = new TempSession()
                {
                    TempSessTitle       = temptitle,
                    TempSessDate        = tempdate,
                    TempSessDescription = tempdescr,
                    TempSessCode        = tempcode
                };

                context.TempSessions.Add(session);
                result = Convert.ToBoolean(context.SaveChanges());
            }

            return(result);
        }
コード例 #19
0
        public bool TransferSession(Session session, int userid)
        {
            bool result = false;

            using (var context = new Model1())
            {
                var newsession = new Session()
                {
                    UserID             = userid,
                    SessionTitle       = session.SessionTitle,
                    SessionDate        = session.SessionDate,
                    SessionDescription = session.SessionDescription,
                    UniqueCode         = session.UniqueCode
                };

                context.Sessions.Add(newsession);
                result = Convert.ToBoolean(context.SaveChanges());
            }
            return(result);
        }
コード例 #20
0
 public static void EliminarAlumnoCurso2(this DbSet <AlumnoCurso> dbset, int id)
 {
     try
     {
         using (var ctx = new Model1())
         {
             AlumnoCurso alumnocurso = new AlumnoCurso();
             alumnocurso = ctx.AlumnoCurso.Where(x => x.id == id).FirstOrDefault();
             if (alumnocurso != null)
             {
                 ctx.Entry(alumnocurso).State = EntityState.Deleted;
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
コード例 #21
0
        private void GrabaMembresia(ref DateTime vfecha1, ref DateTime vfecha2)
        {
            using (Model1 bd = new Model1())
            {
                var user = (from dd in bd.Zk_MembresiasxSocio
                            where dd.ID == (vMembId)
                            select dd).FirstOrDefault();

                vfecha1 = Convert.ToDateTime(DtpInicio.Text);
                vfecha2 = Convert.ToDateTime(DtpTermino.Text);

                user.FechaInicio       = vfecha1;
                user.FechaFinal        = vfecha2;
                user.Referencia        = TxtReferencia.Text;
                user.FechaModificacion = DateTime.Now.Date;
                user.AutorizacionesID  = Convert.ToInt32(ctr_AyuAutorizacion.Codigo);

                bd.SaveChanges();
            }
        }
コード例 #22
0
ファイル: Form1.cs プロジェクト: OliviaDenbuW/Desktop
        private void DeleteContact()
        {
            int contactId = GetContactId();

            using (var db = new Model1())
            {
                ContactInformation dbModel = (from contact in db.ContactInformation
                                              where contact.ContactID == contactId
                                              select contact).SingleOrDefault();

                db.ContactInformation.Remove(dbModel);

                db.SaveChanges();
            }



            MessageBox.Show("Contact has successfully been deleted");
            GetAllAddresses();
        }
コード例 #23
0
        public JsonResult SaveForm(Form form)
        {
            var result = false;

            if (form.id > 0)
            {
                return(Json(form, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Form f = new Form();
                f.ad    = form.ad;
                f.soyad = form.soyad;
                f.yas   = form.yas;
                db.Forms.Add(f);
                db.SaveChanges();
                result = true;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #24
0
 public static void updateFormula(string formular, string name, string thoiGian)
 {
     using (var db = new Model1())
     {
         DateTime batDau = DateTime.MinValue;
         if (db.CongThucTongSanLuongs.Count() != 0)
         {
             batDau = db.CongThucTongSanLuongs.OrderByDescending(x => x.ThoiGianKetThuc).Select(x => x.ThoiGianKetThuc).First().AddDays(1);
         }
         var item = new CongThucTongSanLuong()
         {
             Ten             = name,
             CongThuc        = formular,
             ThoiGianBatDau  = batDau,
             ThoiGianKetThuc = DateTime.ParseExact(thoiGian, "dd/MM/yyyy", null)
         };
         db.CongThucTongSanLuongs.Add(item);
         db.SaveChanges();
     }
 }
コード例 #25
0
ファイル: SedeBl.cs プロジェクト: elkrlos10/Calendar-365
        public void ActualizarRegistro(Sede oSede)
        {
            Model1 entity = new Model1();

            var Item = (from i in entity.Sede
                        where i.IdSede == oSede.IdSede
                        select i).First();

            Item.Nombre_Sede = oSede.Nombre_Sede;

            Item.Direccion = oSede.Direccion;

            Item.IdMunicipio = oSede.IdMunicipio;

            Item.Codigo = oSede.Codigo;

            Item.TipoSede = oSede.TipoSede;

            entity.SaveChanges();
        }
コード例 #26
0
ファイル: Service1.cs プロジェクト: Maksym-Rohach/Project
 public void AddMark(int mark, Student student, Subject sub)
 {
     try
     {
         Mark _mark = new Mark();
         using (Model1 db = new Model1())
         {
             db.Students.Attach(student);
             db.Subjects.Attach(sub);
             _mark.student = student;
             _mark.subject = sub;
             db.Marks.Add(_mark);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message);
     }
 }
コード例 #27
0
        public void ActualizarRegistro(Instructor oInstructor)
        {
            Model1 entity = new Model1();

            var Item = (from i in entity.Instructor
                        where i.IdInstructor == oInstructor.IdInstructor
                        select i).First();

            Item.Nombre         = oInstructor.Nombre;
            Item.Apellido       = oInstructor.Apellido;
            Item.Cedula         = oInstructor.Cedula;
            Item.Email          = oInstructor.Email;
            Item.Estado         = oInstructor.Estado;
            Item.TipoContrato   = oInstructor.TipoContrato;
            Item.Telefono       = oInstructor.Telefono;
            Item.TipoInstructor = oInstructor.TipoInstructor;
            Item.IdArea         = oInstructor.IdArea;
            Item.Estado         = true;
            entity.SaveChanges();
        }
コード例 #28
0
        public static int ResimKaydet(HttpPostedFileBase Resim, HttpContextBase ctx)
        {
            Model1 db = new Model1();


            kullanici k = (kullanici)ctx.Session["Kullanici"];

            int kucukWidth  = Convert.ToInt32(ConfigurationManager.AppSettings["kw"]);
            int kucukHeight = Convert.ToInt32(ConfigurationManager.AppSettings["kh"]);
            int ortaWidth   = Convert.ToInt32(ConfigurationManager.AppSettings["ow"]);
            int ortaHeight  = Convert.ToInt32(ConfigurationManager.AppSettings["oh"]);
            int buyukWidth  = Convert.ToInt32(ConfigurationManager.AppSettings["bw"]);
            int buyukHeight = Convert.ToInt32(ConfigurationManager.AppSettings["bh"]);

            string newName = Path.GetFileNameWithoutExtension(Resim.FileName) + "-" + Guid.NewGuid() + Path.GetExtension(Resim.FileName);

            Image  orjRes   = Image.FromStream(Resim.InputStream);
            Bitmap kucukRes = new Bitmap(orjRes, kucukWidth, kucukHeight);
            Bitmap ortaRes  = new Bitmap(orjRes, ortaWidth, ortaHeight);
            Bitmap buyukRes = new Bitmap(orjRes, buyukWidth, buyukHeight);

            kucukRes.Save(ctx.Server.MapPath("~/Content/Resimler/Kucuk/" + newName));
            ortaRes.Save(ctx.Server.MapPath("~/Content/Resimler/Orta/" + newName));
            buyukRes.Save(ctx.Server.MapPath("~/Content/Resimler/Buyuk/" + newName));


            resim dbRes = new resim();

            dbRes.Ad            = Resim.FileName;
            dbRes.BuyukResimYol = "/Content/Resimler/Buyuk/" + newName;
            dbRes.OrtaResimYol  = "/Content/Resimler/Orta/" + newName;
            dbRes.KucukResimYol = "/Content/Resimler/Kucuk/" + newName;

            dbRes.EklenmeTarihi = DateTime.Now;
            dbRes.EkleyenID     = k.Id;

            db.resim.Add(dbRes);
            db.SaveChanges();

            return(dbRes.Id);
        }
コード例 #29
0
        public ActionResult Login()
        {
            string userid     = Request["ID"];
            string password   = Request["password"];
            string repassword = Request["repassword"];

            if (userid != null)
            {
                int studentID = int.Parse(userid);

                if (compare(int.Parse(password), int.Parse(repassword)) == 0)
                {
                    Model1 ctxx  = new Model1();
                    var    query = (from s in ctxx.student where s.StudentID == studentID select s).FirstOrDefault();
                    if (query == null)
                    {
                        Model1 ctx  = new Model1();
                        var    user = new student();
                        user.StudentID = int.Parse(userid);
                        user.Password  = password;
                        ctx.student.Add(user);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        byte[] s       = new byte[1024];
                        int    t       = ErrorMessage(0, ref s[0]);//用字节数组接收动态库传过来的字符串
                        string message = System.Text.Encoding.Default.GetString(s, 0, s.Length);
                        return(Content(message));
                    }
                }
                else
                {
                    byte[] s       = new byte[1024];
                    int    t       = ErrorMessage(1, ref s[0]);//用字节数组接收动态库传过来的字符串
                    string message = System.Text.Encoding.Default.GetString(s, 0, s.Length);
                    return(Content(message));
                }
            }
            return(View());
        }
コード例 #30
0
        public ActionResult Register(CustomerModel customerModel)
        {
            ViewBag.Success = "";
            if (ModelState.IsValid)
            {
                Customer cus = new Customer();
                cus.Username = customerModel.Username;
                cus.Password = customerModel.Password;
                cus.Name     = customerModel.Name;
                cus.Email    = customerModel.Email;
                cus.Phone    = customerModel.Phone;
                cus.Address  = customerModel.Address;

                SHA256 encode        = new SHA256CryptoServiceProvider();
                Byte[] originalBytes = ASCIIEncoding.Default.GetBytes(cus.Password);
                Byte[] encodedBytes  = encode.ComputeHash(originalBytes);
                cus.Password = BitConverter.ToString(encodedBytes);

                var checkUsername = (from p in db.Customers
                                     where p.Username == customerModel.Username
                                     select p).SingleOrDefault();
                if (checkUsername != null)
                {
                    ViewBag.ErrorUsername = "******";
                    return(View());
                }

                var checkEmail = (from p in db.Customers
                                  where p.Email == customerModel.Email
                                  select p).SingleOrDefault();
                if (checkEmail != null)
                {
                    ViewBag.ErrorEmail = "Email has aldready exited";
                    return(View());
                }
                db.Customers.Add(cus);
                db.SaveChanges();
                ViewBag.Success = "Success!";
            }
            return(View());
        }