public IHttpActionResult PutLecturer(LecturerDTO lecturerDTO)
      {
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState));
          }

          //var lecturer = lecturerRepo.Get(id);

          //if (lecturer == null)
          //    return BadRequest("Invalid parameters");

          //lecturer.FirstName = firstName;
          //lecturer.LastName = lastName;

          Lecturer lecturer = Mapper.Map <Lecturer>(lecturerDTO);

          lecturerRepo.Update(lecturer);

          try
          {
              lecturerRepo.Save();
              return(Ok(lecturer));
          }
          catch (DbUpdateConcurrencyException)
          {
          }

          return(StatusCode(HttpStatusCode.NoContent));
      }
        public ActionResult AboutLecturer(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ValidationException("id doesn't exist", "");
            }
            LecturerDTO lecturerDto = lecturerService.GetLecturer(Convert.ToInt32(id));


            var mapper   = new MapperConfiguration(cfg => cfg.CreateMap <LecturerDTO, LecturerViewModel>()).CreateMapper();
            var lecturer = mapper.Map <LecturerDTO, LecturerViewModel>(lecturerDto);

            return(View(lecturer));
        }
      public IHttpActionResult GetLecturer(int id)
      {
          Lecturer Lecturer = lecturerRepo.Get(id);

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



          LecturerDTO LecturerDTO = Mapper.Map <LecturerDTO>(Lecturer);

          return(Ok(LecturerDTO));
      }
Esempio n. 4
0
        public IHttpActionResult GetLecturer(int id)
        {
            Lecturer Lecturer = (Lecturer)lecturerRepo.Find(id);

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

            Mapper.Initialize(c => c.CreateMap <Lecturer, LecturerDTO>());

            LecturerDTO LecturerDTO = Mapper.Map <LecturerDTO>(Lecturer);

            return(Ok(LecturerDTO));
        }
Esempio n. 5
0
        public IHttpActionResult PostLecturer(LecturerDTO LecturerDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Mapper.Initialize(c => c.CreateMap <LecturerDTO, Lecturer>());

            Lecturer Lecturer = Mapper.Map <Lecturer>(LecturerDTO);

            lecturerRepo.Add(Lecturer);
            lecturerRepo.Save();

            return(CreatedAtRoute("DefaultApi", new { id = Lecturer.ID }, Lecturer));
        }
        public void AddLecturer(LecturerDTO lecturerDTO, int depId)
        {
            var      dep      = Database.Departments.Get(depId);
            Lecturer lecturer = new Lecturer
            {
                FirstName     = lecturerDTO.FirstName,
                SecondName    = lecturerDTO.SecondName,
                Department    = dep,
                LecturerEmail = lecturerDTO.LecturerEmail,
                Information   = lecturerDTO.Information,
                ImageName     = lecturerDTO.ImageName,
                Image         = lecturerDTO.Image
            };

            Database.Lecturers.Create(lecturer);
            Database.Save();
        }
        /// <summary>
        /// Method EditLecturer
        /// is used to edit Lecturer in database
        /// </summary>
        /// <param name="lecturerDTO"></param>
        /// <param name="depId">Department Id</param>
        public void EditLecturer(LecturerDTO lecturerDTO, int depId)
        {
            var      dep      = Database.Departments.Get(depId);
            Lecturer lecturer = new Lecturer
            {
                FirstName     = lecturerDTO.FirstName,
                SecondName    = lecturerDTO.SecondName,
                LecturerId    = lecturerDTO.LecturerId,
                Department    = dep,
                Information   = lecturerDTO.Information,
                Image         = lecturerDTO.Image,
                ImageName     = lecturerDTO.ImageName,
                LecturerEmail = lecturerDTO.LecturerEmail,
                Courses       = Database.Lecturers.Get(lecturerDTO.LecturerId).Courses
            };

            Database.Lecturers.Update(lecturer);
        }
      public IHttpActionResult PostLecturer(LecturerDTO lecturerDTO)
      {
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState));
          }

          Lecturer lecturer = Mapper.Map <Lecturer>(lecturerDTO);

          lecturerRepo.Add(lecturer);

          try
          {
              lecturerRepo.Save();
              return(Ok(lecturer));
          }
          catch
          {
              return(BadRequest("Failed to add Lecturer"));
          }

          //return CreatedAtRoute("DefaultApi", new { id = Lecturer.ID }, Lecturer);
          //return Ok(lecturer);
      }
Esempio n. 9
0
        public IHttpActionResult PutLecturer(int id, LecturerDTO LecturerDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != LecturerDTO.ID)
            {
                return(BadRequest());
            }

            Mapper.Initialize(c => c.CreateMap <LecturerDTO, Lecturer>());

            Lecturer Lecturer = Mapper.Map <Lecturer>(LecturerDTO);

            lecturerRepo.Update(Lecturer);

            try
            {
                lecturerRepo.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LecturerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 10
0
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Ваш пароль изменен."
                : message == ManageMessageId.SetPasswordSuccess ? "Пароль задан."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Настроен поставщик двухфакторной проверки подлинности."
                : message == ManageMessageId.Error ? "Произошла ошибка."
                : message == ManageMessageId.AddPhoneSuccess ? "Ваш номер телефона добавлен."
                : message == ManageMessageId.RemovePhoneSuccess ? "Ваш номер телефона удален."
                : "";



            var userId = User.Identity.GetUserId();

            ApplicationUserManager userManager = HttpContext.GetOwinContext()
                                                 .GetUserManager <ApplicationUserManager>();
            var            email = userManager.GetEmail(userId);
            IList <string> roles = new List <string>();

            if (!string.IsNullOrEmpty(userId))
            {
                roles = userManager.GetRoles(userId);
            }
            var model = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
            };

            if (roles.Contains("admin"))
            {
                model.Email = email;
                model.Role  = "admin";
            }
            else if (roles.Contains("lecturer"))
            {
                LecturerDTO lecturer = lecturerService.GetLecturers().First(x => x.LecturerEmail == email);
                model.FirstName   = lecturer.FirstName;
                model.SecondName  = lecturer.SecondName;
                model.Department  = lecturer.Department.DepartmentName;
                model.Description = lecturer.Information;
                model.Role        = "lecturer";
                model.Id          = lecturer.LecturerId;
                model.Email       = lecturer.LecturerEmail;
                model.Image       = lecturer.Image;
                model.ImageName   = lecturer.ImageName;
            }
            else if (roles.Contains("student"))
            {
                StudentDTO student = studentService.GetStudents().First(x => x.StudentEmail == email);
                model.FirstName   = student.FirstName;
                model.SecondName  = student.SecondName;
                model.StudentTerm = student.StudentTerm;
                model.Description = "";
                model.Role        = "student";
                model.Id          = student.StudentId;
                model.Email       = student.StudentEmail;
                model.isBanned    = student.IsBanned;
            }

            return(View(model));
        }