コード例 #1
0
        public ActionResult AddStudent(tbl_Student model)
        {
            tbl_Student obj = new tbl_Student();

            if (ModelState.IsValid)
            {
                obj.ID          = model.ID;
                obj.Name        = model.Name;
                obj.Fname       = model.Fname;
                obj.Email       = model.Email;
                obj.Mobile      = model.Mobile;
                obj.Description = model.Description;

                if (model.ID == 0)
                {
                    dbObj.tbl_Student.Add(obj);
                    dbObj.SaveChanges();
                }
                else
                {
                    dbObj.Entry(obj).State = EntityState.Modified;
                    dbObj.SaveChanges();
                }
            }
            ModelState.Clear();

            return(View("Student"));
        }
コード例 #2
0
        public ActionResult AddSkill(string skillName)      //Test
        {
            using (dbEntities db = new dbEntities())
            {
                var newSkill = db.SkillsLogs.Where(o => o.Name.Equals(skillName.ToLower())).Any(); //Check if skill doesn't exist
                if (!newSkill)                                                                     //Adds skill to skill log
                {
                    db.SkillsLogs.Add(new SkillsLog {
                        Name = skillName.ToLower()
                    });
                    db.SaveChanges();
                }
                object test = Session["loginid"];

                int skillID  = db.SkillsLogs.Where(o => o.Name.Equals(skillName.ToLower())).First().Id;    //skill id
                int userID   = (int)Session["loginid"];
                var hasSkill = db.UserSkills.Where(o => o.SkillId == skillID && o.UserId == userID).Any(); //Check user already has skill


                if (!hasSkill)//Add Skill
                {
                    int id = Convert.ToInt32(Session["loginid"]);
                    db.UserSkills.Add(new UserSkill {
                        SkillId = skillID, UserId = id
                    });
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("GetUserById", "UserBio", new { id = (int)Session["Loginid"] }));
            //return View();
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: rrondosa/NetPrueba
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            //alta
            dbEntities ctx = new dbEntities();
            Empleado   em  = new Empleado();

            em.apellido = "perez";
            em.nombre   = "Juan";
            ctx.Empleado.Add(em);
            ctx.SaveChanges();

            //modificar
            int myid = 1;
            //busco el objeto
            Empleado em2 = ctx.Empleado.Find(myid);

            em2.nombre = "Beto";
            ctx.SaveChanges();

            /*
             * se puede consultar por su estado obj:
             * -unchanged
             * -added
             * -modified
             * -deleted
             * -detached
             */

            return(View());
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "id,start_time,map,result,is_broadcasted,is_registration_open,fk_first_team,fk_second_team,fk_tournament,fk_place,fk_betting,fk_ticket")] match match)
        {
            int d;

            if (ModelState.IsValid)
            {
                if (Session["TournamentId"] != null)
                {
                    match.fk_tournament = (int)Session["TournamentId"];
                    d = (int)Session["TournamentId"];
                    Session.Remove("TounamentId");
                    db.matches.Add(match);
                    db.SaveChanges();
                    return(RedirectToAction("Details", "Tournaments", new { id = d }));
                }
                else
                {
                    return(HttpNotFound());
                }
            }

            ViewBag.fk_betting     = new SelectList(db.bettings, "id", "id", match.fk_betting);
            ViewBag.fk_tournament  = new SelectList(db.tournaments, "id", "name", match.fk_tournament);
            ViewBag.fk_ticket      = new SelectList(db.tickets, "id", "description", match.fk_ticket);
            ViewBag.fk_place       = new SelectList(db.places, "id", "id", match.fk_place);
            ViewBag.fk_ticket      = new SelectList(db.tickets, "id", "description", match.fk_ticket);
            ViewBag.fk_first_team  = new SelectList(db.teams, "id", "name", match.fk_first_team);
            ViewBag.fk_second_team = new SelectList(db.teams, "id", "name", match.fk_second_team);
            return(View(match));
        }
コード例 #5
0
        public ActionResult CreateMsg(UserMessagesVeiwModel model)
        {
            using (dbEntities db = new dbEntities())
            {
                Boolean     ValidEmail = false;
                List <User> users      = db.Users.ToList();
                int         receiverid = -1;
                if (model.Employerid != null)
                {
                    receiverid = (int)model.Employerid;
                }
                foreach (var u in users)
                {
                    if (u.Email.Equals((string)model.Employeremail))
                    {
                        ValidEmail = true;
                        receiverid = u.Id;
                    }
                }
                if (ModelState.IsValid && ValidEmail == true)
                {
                    int       senderid = (int)Session["loginid"];
                    int       Msgid    = db.Messagings.Count();
                    Messaging temp     = new Messaging()
                    {
                        Id         = Msgid + 1,
                        Date       = DateTime.Now,
                        SenderId   = senderid,
                        ReceiverId = receiverid,
                        Subject    = model.Msg.Subject,
                        JobId      = model.Msg.JobId,
                        Message    = model.Msg.Message
                    };
                    db.Users.Where(o => o.Id == senderid).Single().Messagings1.Add(temp);
                    db.SaveChanges();

                    //make another message for the receiver of the message. must do this since the two messages must have different message ids
                    Msgid = db.Messagings.Count();
                    Messaging temp2 = new Messaging()
                    {
                        Id         = Msgid + 1,
                        Date       = DateTime.Now,
                        SenderId   = senderid,
                        ReceiverId = receiverid,
                        Subject    = model.Msg.Subject,
                        JobId      = model.Msg.JobId,
                        Message    = model.Msg.Message
                    };

                    db.Users.Where(o => o.Id == receiverid).Single().Messagings.Add(temp);
                    db.SaveChanges();
                    return(RedirectToAction("MessagePageDisplayStd", "Msg"));
                }
                model.ErrorLoadingPage = "Please enter a valid email";
                return(View("~/Views/Msg/MsgView.cshtml", model)); //redirect to message page with error output on page as well
            }
        }
コード例 #6
0
 public ActionResult DilEkle(string ad) // Post form metoduyla veriyi parametreye atar.
 {
     model.diller.Add(new diller()
     {
         ad = ad
     });                                // model değişkenine ekleniyor.
     model.SaveChanges();               // ve sdf uzantılı veritabanına değişiklikler gerçekleştiriliyor.
     return(RedirectToAction("Index")); // Daha sonra Index action'ına yönleniyor.
 }
コード例 #7
0
 //api/student
 public IHttpActionResult Post([FromBody] Student _std)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Không thành công!"));
     }
     _db.Students.Add(_std);
     _db.SaveChanges();
     return(Ok(_std));
 }
コード例 #8
0
        public ActionResult Create([Bind(Include = "VOppID,OName,ODate,OCenter,OSkills")] Odb odb)
        {
            if (ModelState.IsValid)
            {
                db.Odbs.Add(odb);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(odb));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "dni,nombre,email,fecha_nacimiento")] Persona persona)
        {
            if (ModelState.IsValid)
            {
                db.Persona.Add(persona);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(persona));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "id,isTangible,category,assetType,assetName,assetDescription,assetState,assetLocation,acquisitionValue,warrantyTime,assetLifeTime,deprecation,salvageValue,acquisitionDate,registrationDate,picture")] Asset asset)
        {
            if (ModelState.IsValid)
            {
                db.Asset.Add(asset);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(asset));
        }
コード例 #11
0
        public ActionResult Create(Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
コード例 #12
0
        public ActionResult Create([Bind(Include = "id,firstName,middleName,lastName1,lastName2,birthDate,employeeState,startDate,picture")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employee.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
コード例 #13
0
        public ActionResult Create([Bind(Include = "Id,Name,Title,Text,Pay,Contact,Adress")] Ads ads)
        {
            if (ModelState.IsValid)
            {
                db.Ads.Add(ads);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ads));
        }
コード例 #14
0
        public ActionResult Create([Bind(Include = "Id,baslik,isim")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.CategorySet.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #15
0
        public ActionResult Create([Bind(Include = "id,name,fk_skinsInGiveaway")] skin skin)
        {
            if (ModelState.IsValid)
            {
                db.skins.Add(skin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(skin));
        }
コード例 #16
0
        public ActionResult Create([Bind(Include = "Id,Title")] UserTypeSet userTypeSet)
        {
            if (ModelState.IsValid)
            {
                db.UserTypeSet.Add(userTypeSet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userTypeSet));
        }
コード例 #17
0
        public ActionResult CreateCategory([Bind(Include = "idCategoria,nome")] Categoria categoria)
        {
            if (ModelState.IsValid)
            {
                db.Categoria.Add(categoria);
                db.SaveChanges();
                return(RedirectToAction("IndexCategory"));
            }

            return(View(categoria));
        }
コード例 #18
0
        public ActionResult Create([Bind(Include = "id,branchName,branchDescription,province,canton,district,branchLocation,branchState")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                db.Branch.Add(branch);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(branch));
        }
コード例 #19
0
        public ActionResult Create([Bind(Include = "id,first_name,last_name,sex,email,rating,age,country,assists,headshots,damage_per_second,maps_played,round_number,total_kills,total_deaths,fk_team")] player player)
        {
            if (ModelState.IsValid)
            {
                db.players.Add(player);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.fk_team = new SelectList(db.teams, "id", "name", player.fk_team);
            return(View(player));
        }
コード例 #20
0
        public ActionResult Create([Bind(Include = "Id,UserTypeId,Name,Mail,Password")] UserSet userSet)
        {
            if (ModelState.IsValid)
            {
                db.UserSet.Add(userSet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserTypeId = new SelectList(db.UserTypeSet, "Id", "Title", userSet.UserTypeId);
            return(View(userSet));
        }
コード例 #21
0
        public ActionResult CreateProduct([Bind(Include = "idProduto,nome,descricao,preco,idCategoria,quantidade,foto,ativo,promo")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                db.Produto.Add(produto);
                db.SaveChanges();
                return(RedirectToAction("IndexProduct"));
            }

            ViewBag.idCategoria = new SelectList(db.Categoria, "idCategoria", "nome", produto.idCategoria);
            return(View(produto));
        }
コード例 #22
0
        public ActionResult Create([Bind(Include = "username,userPassword,employeeID,accessLevel")] UserLogin userLogin)
        {
            if (ModelState.IsValid)
            {
                db.UserLogin.Add(userLogin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.employeeID = new SelectList(db.Employee, "id", "firstName", userLogin.employeeID);
            return(View(userLogin));
        }
コード例 #23
0
ファイル: Profile.cs プロジェクト: ysodiqakanni/buzz_a_tutor
        public ViewModels.Profile.New SaveNew(int id, FormCollection frm)
        {
            var ret = new ViewModels.Profile.New();

            using (var conn = new dbEntities())
            {
                var firstName = (frm["Fname"] ?? "").Trim();
                var lastName  = (frm["Lname"] ?? "").Trim();
                var email     = (frm["Email"] ?? "").Trim();

                if (string.IsNullOrEmpty(firstName))
                {
                    throw new Exception("First name required.");
                }

                if (string.IsNullOrEmpty(lastName))
                {
                    throw new Exception("Last name required.");
                }

                if (string.IsNullOrEmpty(email))
                {
                    throw new Exception("Email required.");
                }

                if (!Helpers.Strings.EmailValid(email))
                {
                    throw new Exception("Email not valid.");
                }

                var accountDetails = new Account()
                {
                    AccountType_ID = (int)Constants.Types.AccountTypes.Student,
                    Fname          = firstName,
                    Lname          = lastName,
                    Email          = email,
                    Password       = Helpers.PasswordStorage.CreateHash("")
                };
                conn.Accounts.Add(accountDetails);
                conn.SaveChanges();

                ret.familyMemeber = new FamilyMember()
                {
                    Account_ID = accountDetails.ID,
                    Parent_ID  = id,
                };
                conn.FamilyMembers.Add(ret.familyMemeber);
                conn.SaveChanges();
            }

            return(ret);
        }
コード例 #24
0
        public ActionResult Create([Bind(Include = "Id,UserSetId,AdsId,Name,Title")] Evaluation evaluation)
        {
            if (ModelState.IsValid)
            {
                db.EvaluationSet.Add(evaluation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserSetId = new SelectList(db.UserSet, "Id", "Name", evaluation.UserSetId);
            ViewBag.AdsId     = new SelectList(db.Ads, "Id", "Name", evaluation.AdsId);
            return(View(evaluation));
        }
コード例 #25
0
        public ActionResult Create([Bind(Include = "Id,AccountNumber,AccountBalance,AppUserId,AccTypeId")] AtmAccount atmAccount)
        {
            if (ModelState.IsValid)
            {
                atmAccount.AppUserId = User.Identity.GetUserId();
                db.AtmAccounts.Add(atmAccount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AccTypeId = new SelectList(db.AccTypes, "Id", "AccountType", atmAccount.AccTypeId);
            return(View(atmAccount));
        }
コード例 #26
0
        public ActionResult Create([Bind(Include = "employeeId,branchId,department,position")] WorksAt worksAt)
        {
            if (ModelState.IsValid)
            {
                db.WorksAt.Add(worksAt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.branchId   = new SelectList(db.Branch, "id", "branchName", worksAt.branchId);
            ViewBag.employeeId = new SelectList(db.Employee, "id", "firstName", worksAt.employeeId);
            return(View(worksAt));
        }
コード例 #27
0
        public ActionResult Create([Bind(Include = "Id,UserSetId,AdsId,Pay,Method")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                db.PaymentSet.Add(payment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserSetId = new SelectList(db.UserSet, "Id", "Name", payment.UserSetId);
            ViewBag.AdsId     = new SelectList(db.Ads, "Id", "Name", payment.AdsId);
            return(View(payment));
        }
コード例 #28
0
        public ActionResult Create([Bind(Include = "id,coefficient,fk_users_bets,fk_match,team_name")] betting betting)
        {
            if (ModelState.IsValid)
            {
                db.bettings.Add(betting);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.fk_users_bets = new SelectList(db.users_bets, "id", "id", betting.fk_users_bets);
            ViewBag.fk_match      = new SelectList(db.matches, "id", "map", betting.fk_match);
            return(View(betting));
        }
コード例 #29
0
        public ActionResult Create([Bind(Include = "id,name,wins,defeats,maps_played,round_number,total_kills,total_deaths,fk_match,fk_player")] team team)
        {
            if (ModelState.IsValid)
            {
                db.teams.Add(team);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.fk_match  = new SelectList(db.matches, "id", "map", team.fk_match);
            ViewBag.fk_player = new SelectList(db.players, "id", "first_name", team.fk_player);
            return(View(team));
        }
コード例 #30
0
        public ActionResult Create([Bind(Include = "id,start_time,finish_time,name,fk_program,fk_tournament")] eventt eventt)
        {
            if (ModelState.IsValid)
            {
                db.eventts.Add(eventt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.fk_tournament = new SelectList(db.tournaments, "id", "name", eventt.fk_tournament);
            ViewBag.fk_program    = new SelectList(db.programs, "id", "name", eventt.fk_program);
            return(View(eventt));
        }
コード例 #31
0
ファイル: HomeController.cs プロジェクト: thomasbrad/testmvc
 public ActionResult Email(Email email)
 {
     var db = new dbEntities();
     db.AddToForwardedEmails(new ForwardedEmail()
                                 {
                                     Created = DateTime.Now,
                                     From = email.From,
                                     Plain = email.Plain,
                                     Subject = email.Subject
                                 });
     db.SaveChanges();
     return new EmptyResult();
 }