public virtual TEntity RemoveEntity(TEntity entity)
 {
     if (_context.Entry(entity).State == EntityState.Detached)
     {
         _context.Set <TEntity>().Attach(entity);
     }
     _context.Set <TEntity>().Remove(entity);
     return(entity);
 }
Exemple #2
0
        private void save_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(nameTextBox.Text) || string.IsNullOrEmpty(nameTextBox.Text) ||
                string.IsNullOrEmpty(surnameTextBox.Text) || string.IsNullOrEmpty(otcTextBox.Text) || string.IsNullOrEmpty(ageBox.Text))
            {
                MessageBox.Show("Пожалуйста заполните поля!");
                return;
            }

            try
            {
                using (MsSqlContext db = new MsSqlContext())
                {
                    if (!int.TryParse(ageBox.Text, out var ages) || int.Parse(ageBox.Text) > 150)
                    {
                        MessageBox.Show("Введите правильное значение возраста (от 1 до 150)!");
                        return;
                    }

                    MyAcc.SelectedUser.user_name       = nameTextBox.Text;
                    MyAcc.SelectedUser.user_surname    = surnameTextBox.Text;
                    MyAcc.SelectedUser.user_otc        = otcTextBox.Text;
                    MyAcc.SelectedUser.Age             = int.Parse(ageBox.Text);
                    db.Entry(MyAcc.SelectedUser).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            Close();
        }
Exemple #3
0
        public async Task DeleteAsync(object id)
        {
            TModel entity = await FindAsync(id);

            if (entity != null)
            {
                _context.Entry(entity).State = EntityState.Deleted;
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Address")] CompanyModel companyModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(companyModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(companyModel));
 }
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Age")] EmployeeModel employeeModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeeModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employeeModel));
 }
Exemple #6
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,hall_name,type,number_of_rows,number_of_seats_in_a_row")] hall hall)
        {
            if (ModelState.IsValid)
            {
                db.Entry(hall).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(hall));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Country,budget,style,release_date,age_rating,duration,distributor,regisseur,film_name")] film film)
        {
            if (ModelState.IsValid)
            {
                db.Entry(film).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(film));
        }
Exemple #8
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,date_of_session,filmname,time_of_session,hallname,hallId,filmId,price_of_tickets")] sessions sessions)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sessions).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.filmId = new SelectList(db.films, "Id", "film_name", sessions.filmId);
            ViewBag.hallId = new SelectList(db.halls, "Id", "hall_name", sessions.hallId);
            return(View(sessions));
        }
        public T Update(T obj)
        {
            if (!Exists(obj.Id))
            {
                return(null);
            }

            T result = dataSet.SingleOrDefault(prop => prop.Id.Equals(obj.Id));

            try
            {
                _context.Entry(result).CurrentValues.SetValues(obj);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(obj);
        }
        public async Task <ActionResult> BuyTicket(int id)
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                places places = await db.places_list.FindAsync(id);

                places.status = "Куплено";
                var user = db.Users.Where(c => c.Email == User.Identity.Name).FirstOrDefault();
                places.UserId = user.Id;
                DateTime data = new DateTime();
                data = DateTime.Now;
                places.date_of_operation        = data;
                db.Entry <places>(places).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "sessions"));
            }
        }
Exemple #11
0
        public async Task <ActionResult> Edit([Bind(Include = "Id, Email,Password, user_surname, user_name,user_otc, Age")] User user)
        {
            if (User.Identity.IsAuthenticated == true)
            {
                if (ModelState.IsValid)
                {
                    using (MsSqlContext dd = new MsSqlContext())
                    {
                        var users = dd.Users.FirstOrDefault(c => c.Email == User.Identity.Name);
                        user.Password = users.Password;
                    }
                    user.Email           = User.Identity.Name;
                    db.Entry(user).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details"));
                }
            }
            else
            {
                return(RedirectToAction("Login"));
            }
            return(View(user));
        }
Exemple #12
0
        public async Task <bool> UpdateAsync(object entity)
        {
            await Task.Run(() => _context.Entry(entity).State = EntityState.Modified);

            return(true);
        }
Exemple #13
0
 public void Update(T obj)
 {
     context.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     context.SaveChanges();
 }
Exemple #14
0
        public ActionResult ChangePassword(ChangePassModel model)
        {
            if (ModelState.IsValid)
            {
                User user;
                user = db.Users.FirstOrDefault(u => u.Email == User.Identity.Name);
                if (user != null)
                {
                    if (user.Email == User.Identity.Name)
                    {
                        using (MsSqlContext db = new MsSqlContext())
                        {
                            byte[] bytes = Encoding.Unicode.GetBytes(model.Password);
                            MD5CryptoServiceProvider CSP =
                                new MD5CryptoServiceProvider();

                            byte[] byteHash = CSP.ComputeHash(bytes);
                            model.Password = string.Empty;
                            foreach (byte b in byteHash)
                            {
                                model.Password += string.Format("{0:x2}", b);
                            }
                            if (model.Password == user.Password)
                            {
                                byte[] bytesnew = Encoding.Unicode.GetBytes(model.Password_new);
                                MD5CryptoServiceProvider CSPnew =
                                    new MD5CryptoServiceProvider();

                                byte[] byteHashnew = CSPnew.ComputeHash(bytesnew);
                                model.Password_new = string.Empty;
                                foreach (byte b in byteHashnew)
                                {
                                    model.Password_new += string.Format("{0:x2}", b);
                                }

                                byte[] bytesconf = Encoding.Unicode.GetBytes(model.ConfirmPassword);
                                MD5CryptoServiceProvider CSPconf =
                                    new MD5CryptoServiceProvider();

                                byte[] byteHashconf = CSP.ComputeHash(bytesconf);
                                model.ConfirmPassword = string.Empty;
                                foreach (byte b in byteHashconf)
                                {
                                    model.ConfirmPassword += string.Format("{0:x2}", b);
                                }
                                if (model.ConfirmPassword == model.Password_new)
                                {
                                    user.Password        = model.ConfirmPassword;
                                    db.Entry(user).State = EntityState.Modified;
                                    db.SaveChanges();
                                    return(RedirectToAction("Details"));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("Password", "Неверный пароль");
                            }
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Details"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login"));
            }
            return(View(model));
        }