コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,Name")] EventType eventType)
        {
            if (ModelState.IsValid)
            {
                db.EventTypes.Add(eventType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eventType));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,ManafacturerId,Model,Caliber,Weight,BarrelLength,Price")] Weapon weapon)
        {
            if (ModelState.IsValid)
            {
                db.Weapons.Add(weapon);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ManafacturerId = new SelectList(db.Manafacturer, "Id", "Name", weapon.ManafacturerId);
            return(View(weapon));
        }
コード例 #3
0
 public bool Add(Area_Reparacion model)
 {
     try
     {
         _DbContext.Area_Reparacions.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #4
0
 public bool Add(Empleado model)
 {
     try
     {
         _DbContext.Empleados.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #5
0
 public bool Add(Mantenimiento model)
 {
     try
     {
         _DbContext.Mantenimientos.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #6
0
ファイル: FacturaService.cs プロジェクト: carlosdz4/ApiTaller
 public bool Add(Factura model)
 {
     try
     {
         _dbContext.Facturas.Add(model);
         _dbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,Title,Description,StartDate,StartTime,EndDate,EndTime,Location,OrganizerId,EventTypeId")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EventTypeId = new SelectList(db.EventTypes, "Id", "Name", @event.EventTypeId);
            ViewBag.OrganizerId = new SelectList(db.Users, "Id", "FullName", @event.OrganizerId);
            return(View(@event));
        }
コード例 #8
0
 public bool Add(Mecanicos model)
 {
     try
     {
         _DbContext.Mecanicos.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #9
0
 public bool Add(Cliente model)
 {
     try
     {
         _DbContext.Clientes.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #10
0
 public bool Add(Vehiculo model)
 {
     try
     {
         _DbContext.Vehiculos.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #11
0
 public bool Add(Departamentos model)
 {
     try
     {
         _DbContext.Departamentos.Add(model);
         _DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #12
0
        public ActionResult Register(User user)
        {
            var db = new FinalProjectDbContext();

            if (ModelState.IsValid)
            {
                //
                // var Hasher = new PasswordHasher<User>();
                //user.password = Hasher.HashPassword(user, user.password);

                //TryValidateModel(user);

                //var user1 = new User { name = user.name, email = user.email, password = user.password };

                //
                db.Users.Add(user);
                db.SaveChanges();

                return(RedirectToAction("LoginPage", "Home"));
            }

            ViewBag.Errors = ModelState.Values;

            return(View("Index"));
        }
コード例 #13
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    FinalProjectDbContext db = new FinalProjectDbContext();
                    db.Users.Add(new User
                    {
                        AspNetUserId = new Guid(user.Id),
                        FullName     = model.FullName
                    });
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Event"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #14
0
        public IActionResult ChangePrefs(PreferencesViewModel preferencesViewModel)
        {
            if (ModelState.IsValid)
            {
                if (tempUsername != null)
                {
                    User currentUser = context.Users.Single(c => c.Username == tempUsername);

                    UserPrefs currentUserPrefs = context.Preferences.Single(p => p.ID == currentUser.UserPrefsID);

                    currentUserPrefs.UsersPrice     = preferencesViewModel.UsersPrice;
                    currentUserPrefs.UsersArea      = preferencesViewModel.UsersArea;
                    currentUserPrefs.UsersCareLevel = preferencesViewModel.UsersCareLevel;

                    context.Preferences.Update(currentUserPrefs);
                    context.SaveChanges();

                    return(Redirect("/HomePage/Browse"));
                }

                //TODO - return an error letting the user know that he needs to login or register first
                string prefsError = "Please login or register to change preferences.";
                ViewBag.error = prefsError;
                ViewBag.n     = 3;
                return(View(preferencesViewModel));
            }
            return(View(preferencesViewModel));
        }
コード例 #15
0
ファイル: FollowController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult Follow(Follower follow)
        {
            var db = new FinalProjectDbContext();

            //var userid = Convert.ToInt32(Session["User"]);
            follow.created_at = DateTime.Now;
            db.Followers.Add(follow);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = follow.followed_id }));
        }
コード例 #16
0
        public IActionResult AddFavorite(Datum datum)
        {
            AspNetUsers thisUser    = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First();
            UserPlanner userPlanner = new UserPlanner();

            if (ModelState.IsValid)
            {
                userPlanner.UserId      = thisUser.Id;
                userPlanner.Restaurants = datum.restaurant_name;
                userPlanner.Dates       = TempData["dayy"].ToString();
                userPlanner.Notes       = null;
                userPlanner.Weather     = TempData["weather"].ToString();
                userPlanner.Events      = TempData["weatherSum"].ToString();

                _context.UserPlanner.Add(userPlanner);
                _context.SaveChanges();
                return(RedirectToAction("UserPlanner", userPlanner));
            }

            return(RedirectToAction("RestaurantSearch", "XYZ"));
        }
コード例 #17
0
        public IActionResult Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                //Create an object for the newly registered user's preferences and save changes to the database
                UserPrefs newUserPrefs = new UserPrefs()
                {
                    UsersPrice     = registerViewModel.UsersPrice,
                    UsersArea      = registerViewModel.UsersArea,
                    UsersCareLevel = registerViewModel.UsersCareLevel
                };

                context.Preferences.Add(newUserPrefs);
                context.SaveChanges();

                //Convert user's password into a PBKDF2 key for strengthened security
                //Create a new User object and add it to the database
                using (var deriveBytes = new Rfc2898DeriveBytes(registerViewModel.Password, 20))
                {
                    byte[] salt = deriveBytes.Salt;
                    byte[] key  = deriveBytes.GetBytes(20);

                    User newUser = new User(registerViewModel.Username, key, salt, registerViewModel.Email, newUserPrefs);

                    context.Users.Add(newUser);
                    context.SaveChanges();

                    //Keep track of the user in this session
                    tempUsername = registerViewModel.Username;

                    return(Redirect("/Homepage/Index/?id=" + newUser.ID));
                }
            }

            else
            {
                return(View(registerViewModel));
            }
        }
コード例 #18
0
ファイル: FollowController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult Delete()
        {
            var db = new FinalProjectDbContext();
            //var userid = Convert.ToInt32(Session["User"]);

            var id     = Convert.ToInt32(RouteData.Values["id"]);
            var follow = db.Followers.FirstOrDefault(f => f.id == id);

            db.Followers.Remove(follow);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = follow.followed_id }));
        }
コード例 #19
0
ファイル: CommentController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult DeleteComment()
        {
            var db = new FinalProjectDbContext();
            var id = Convert.ToInt32(RouteData.Values["id"]);


            var comment = db.Comments.SingleOrDefault(c => c.id == id);
            var userid  = Convert.ToInt32(comment.Message.Messaged.id);

            db.Comments.Remove(comment);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = userid }));
        }
コード例 #20
0
ファイル: UserController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult Update(User user)
        {
            var db     = new FinalProjectDbContext();
            var userid = Convert.ToInt32(Session["User"]);

            var oldUser = db.Users.SingleOrDefault(u => u.id == userid);

            //oldUser.name = user.name;

            // oldUser.avatar = user.avatar;

            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = userid }));
        }
コード例 #21
0
ファイル: LikeController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult Like()
        {
            var commentid = Convert.ToInt32(RouteData.Values["id"]);
            var userid    = Convert.ToInt32(Session["User"]);

            var db      = new FinalProjectDbContext();
            var comment = db.Comments.FirstOrDefault(c => c.id == commentid);
            var like    = new Like {
                user_id = userid, comment_id = commentid
            };

            db.Likes.Add(like);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = comment.Message.Messaged.id }));
        }
コード例 #22
0
ファイル: CommentController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult PostComment(Comment comment)
        {
            var db     = new FinalProjectDbContext();
            var msg    = db.Messages.First(m => m.id == comment.message_id);
            var pageid = msg.messaged_id; //getting ID of the user that was messaged so that the page will remain the same after comment submission

            var userid = (int)Session["User"];

            comment.user_id    = userid;
            comment.created_at = DateTime.Now;

            db.Comments.Add(comment);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = pageid }));
        }
コード例 #23
0
ファイル: MessageController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult PostMessage(Message message)
        {
            var db       = new FinalProjectDbContext();
            var userid   = (int)Session["User"];                    // user id of the user sending the message
            var postedid = Convert.ToInt32(RouteData.Values["id"]); //user id of the user being messaged

            var msg = new Message {
                message = message.message, messaged_id = postedid, messager_id = userid, created_at = DateTime.Now
            };                                                                                                                           //coulve added the properties to the message object recived from the form , but this method requried less lines of code

            db.Messages.Add(msg);
            db.SaveChanges();


            return(RedirectToAction("UserPage", "Home", new { id = postedid }));
        }
コード例 #24
0
ファイル: MessageController.cs プロジェクト: fsheiikh/C_Sharp
        public ActionResult Delete()
        {
            var db = new FinalProjectDbContext();
            var id = Convert.ToInt32(RouteData.Values["id"]); //id of the message


            var message = db.Messages.SingleOrDefault(m => m.id == id);         //get that message from databse based on the id

            var url = message.Messaged.id;                                      //id of the user whose page we were on (for the redirect)

            var userid = Convert.ToInt32(Session["User"]);                      //user id of user logged in

            var comments = db.Comments.Where(c => c.message_id == id).ToList(); // get comments of teh message we are deleting

            db.Comments.RemoveRange(comments);                                  //delete those comments before deleteign the message
            //The method of deleting comments before the message is most liekly incorrect. implementing a cascading deletetion based on foreign keys would be better

            db.Messages.Remove(message);
            db.SaveChanges();

            return(RedirectToAction("UserPage", "Home", new { id = url }));
        }
コード例 #25
0
 //Create
 public void Create(T item)
 {
     Context.Set <T>().Add(item);
     Context.SaveChanges();
 }