Example #1
0
        public static long UpdateTutor(TutorDTO tutor)
        {
            try
            {
                using (var ctx = new DAL.tutorDBEntities())
                {
                    var dbUser = ctx.Users.FirstOrDefault(x => x.id == tutor.id) ?? throw new Exception($"Пользователя не существует");


                    dbUser.name  = tutor.name;
                    dbUser.email = tutor.email;
                    //dbUser.emailVerified = student.emailVerified;
                    dbUser.birthDate = tutor.birthDate;


                    var dbTutor = ctx.Tutors.FirstOrDefault(x => x.userId == tutor.id) ?? throw new Exception($"Пользователя не существует");

                    dbTutor.Skype         = tutor.Skype;
                    dbTutor.info          = tutor.info;
                    dbTutor.adress        = tutor.adress;
                    dbTutor.avatarId      = tutor.avatarId;
                    dbTutor.education     = tutor.education;
                    dbTutor.qualification = tutor.qualification;
                    dbTutor.isApproved    = tutor.isApproved;
                    ctx.SaveChanges();

                    return(dbUser.id);
                }
            }
            catch (Exception ex)
            {
                throw;
                //return -1;
            }
        }
Example #2
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Lastname,Email,Role")] TutorDTO tutorDTO)
        {
            var TutorDTO = await _context.Tutor.FirstOrDefaultAsync(u => u.Id == tutorDTO.Id);

            if (TutorDTO == null)
            {
                return(NotFound());
            }

            _context.Entry(TutorDTO).CurrentValues.SetValues(tutorDTO);

            try
            {
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetTutor), new { id = tutorDTO.Id }, tutorDTO));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TutorExists(tutorDTO.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Example #3
0
        public static TutorDTO GetTutor(long?id = null, string email = null)
        {
            if (!id.HasValue && string.IsNullOrEmpty(email))
            {
                return(null);
            }
            try
            {
                using (var ctx = new DAL.tutorDBEntities())
                {
                    var dbTutor = ctx.Users.Join(ctx.Tutors,
                                                 u => u.id,
                                                 s => s.userId,
                                                 (u, s) => new
                    {
                        id            = u.id,
                        name          = u.name,
                        email         = u.email,
                        emailVerified = u.emailVerified,
                        passwordHash  = u.passwordHash,
                        passwordSalt  = u.passwordSalt,
                        avatarId      = s.avatarId,
                        Skype         = s.Skype,
                        info          = s.info,
                        adress        = s.adress,
                        education     = s.education,
                        qualification = s.qualification,
                        isApproved    = s.isApproved,
                        rating        = s.rating,
                        birthDate     = u.birthDate,
                        regDate       = u.regDate
                    }).FirstOrDefault(x => x.id == id || x.email == email);
                    if (dbTutor != null)
                    {
                        var tutor = new TutorDTO
                        {
                            id            = dbTutor.id,
                            name          = dbTutor.name,
                            email         = dbTutor.email,
                            emailVerified = dbTutor.emailVerified,
                            avatarId      = dbTutor.avatarId,
                            Skype         = dbTutor.Skype,
                            info          = dbTutor.info,
                            adress        = dbTutor.adress,
                            education     = dbTutor.education,
                            qualification = dbTutor.qualification,
                            isApproved    = dbTutor.isApproved,
                            rating        = dbTutor.rating,
                            birthDate     = dbTutor.birthDate,
                            regDate       = dbTutor.regDate
                        };

                        return(tutor);
                    }

                    throw new Exception($"Пользователь с email: {email} не найден");
                }
            }
            catch (Exception ex)
            {
                //throw;
                return(null);
            }
        }