public async Task <IActionResult> PutUserDetails(decimal id, UserDetails userDetails)
        {
            if (id != userDetails.Id)
            {
                return(BadRequest());
            }

            _context.Entry(userDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <UserDetails> > PutEducation(decimal id, Education education)
        {
            if (id != education.Id)
            {
                return(BadRequest());
            }

            _context.Entry(education).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (EducationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutEmployee([FromRoute] int id, [FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmployeeId)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PutTraining(int id, Training training)
        {
            if (id != training.Id)
            {
                return(BadRequest());
            }

            _context.Entry(training).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrainingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerId)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Email,FighterRank,SparingCount,RankID")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
 public ActionResult Edit([Bind(Include = "ID,RankType")] Rank rank)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rank).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rank));
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "ID,OpponentName,Position,WinLoss,DateOfEvent,StudentID")] SubmissionLog submissionLog)
 {
     if (ModelState.IsValid)
     {
         db.Entry(submissionLog).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(submissionLog));
 }
 public ActionResult Edit([Bind(Include = "Id,RankID,VideoTitle,VideoSrc,IsVideoComplete,VideoRank")] Video video)
 {
     if (ModelState.IsValid)
     {
         db.Entry(video).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(video));
 }
 public void Update(Training item)
 {
     try
     {
         _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         _context.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 11
0
 public void Update(Session entity)
 {
     TrainingContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
     TrainingContext.SaveChanges();
 }
Exemplo n.º 12
0
 public void EditTraining(Training item)
 {
     _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }
 public int UpdateTraining(Training training)
 {
     _dbContext.Entry(training).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     return(Save());
 }
        public ActionResult Execute(int trainingId)
        {
            IEnumerable <Training> t = db.Trainings.
                                       Where(tr => tr.Id == trainingId);

            if (!t.Any())
            {
                return(View("Error"));
            }
            Training training = t.First();

            ViewBag.Training = training;
            IEnumerable <University> universities = db.Universities;

            ViewBag.Universities = universities;

            CheckState state = CheckState.FirstName;
            var        post  = Request.Form;
            //checking and resuming in case of error
            string firstName, secondName, email;
            int    universityId = 1;
            int    year;

            while (true)
            {
                if ((firstName = post["firstName"]) != null)
                {
                    Regex r = new Regex(@"[А-Я]{1,1}[А-Яа-я-]{0,}[а-я]{1,}");
                    Match m = r.Match(firstName);
                    if (m.Value.Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                state = CheckState.SecondName;
                if ((secondName = post["secondName"]) != null)
                {
                    Regex r = new Regex(@"[А-Я]{1,1}[А-Яа-я-]{0,}[а-я]{1,}");
                    Match m = r.Match(secondName);
                    if (m.Value.Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                state = CheckState.Email;
                if ((email = post["email"]) != null)
                {
                    Regex r = new Regex(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})");
                    Match m = r.Match(email);
                    if (m.Value.Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                state = CheckState.University;
                if ((post["university"]) != null)
                {
                    if (!Int32.TryParse(post["university"], out universityId))
                    {
                        break;
                    }
                    if (universityId <= 0)
                    {
                        break;
                    }
                    IEnumerable <University> u = universities.
                                                 Where(university => university.Id == universityId);
                    if (!u.Any())
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                state = CheckState.Year;
                if ((post["year"]) != null)
                {
                    if (!Int32.TryParse(post["year"], out year))
                    {
                        break;
                    }
                    if (year <= 0)
                    {
                        break;
                    }
                    IEnumerable <University> u = universities.
                                                 Where(university => university.Id == universityId).
                                                 Where(university => university.MaxYear >= year);
                    if (!u.Any())
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                //everything is OK
                ViewBag.firstName  = firstName;
                ViewBag.secondName = secondName;
                //check student existance
                IEnumerable <Student> s = db.Students.
                                          Where(st =>
                                                st.FirstName == firstName &&
                                                st.SecondName == secondName &&
                                                st.UniversityId == universityId &&
                                                st.Email == email);
                if (!s.Any())
                {
                    //create new student
                    db.Students.Add(new Student
                    {
                        FirstName    = firstName,
                        SecondName   = secondName,
                        Email        = email,
                        UniversityId = universityId,
                        Grade        = year,
                        Trainings    = new List <Training>(t)
                    });
                    db.SaveChanges();
                }
                else
                {
                    //update existing
                    Student st = s.First();
                    //if already exists
                    if (st.Trainings.Contains(training))
                    {
                        state = CheckState.Exists;
                        break;
                    }
                    st.Trainings.Add(training);
                    db.Entry(st).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(View("Success"));
            }
            //not first entry
            if (post["firstName"] != null)
            {
                switch (state)
                {
                case CheckState.FirstName:
                    ViewBag.Error = "Проверьте правильность ввода имени";
                    break;

                case CheckState.SecondName:
                    ViewBag.Error = "Проверьте правильность ввода фамилии";
                    break;

                case CheckState.Email:
                    ViewBag.Error = "Проверьте правильность ввода электронной почты";
                    break;

                case CheckState.University:
                    ViewBag.Error = "Выберите университет из списка предложенных";
                    break;

                case CheckState.Year:
                    ViewBag.Error = "Проверьте правильность ввода курса";
                    break;

                case CheckState.Exists:
                    ViewBag.Error = "Этот студент уже зарегистрирован на этот тренинг";
                    break;
                }
            }
            else
            {
                ViewBag.Error = "";
            }
            ViewBag.firstName  = post["firstName"] ?? "";
            ViewBag.secondName = post["secondName"] ?? "";
            ViewBag.email      = post["email"] ?? "";
            ViewBag.university = universityId;
            ViewBag.year       = post["year"] ?? "1";
            return(View("Index"));
        }
 public void Update(Training item)
 {
     _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
     //throw new NotImplementedException();
 }