Ejemplo n.º 1
0
        public JsonResult UpdatePerconalData(PersonalDataViewModel model, string avatar)
        {
            if (Roles.IsUserInRole("lector"))
            {
                var modData = new ModifyLecturerViewModel(new Lecturer
                {
                    FirstName  = model.Name,
                    LastName   = model.Surname,
                    MiddleName = model.Patronymic,
                    IsLecturerHasGraduateStudents = model.IsLecturerHasGraduateStudents,
                    IsSecretary = model.IsSecretary,
                    Skill       = model.Skill,
                    User        = new User
                    {
                        UserName     = model.UserName,
                        Avatar       = avatar,
                        About        = model.About,
                        SkypeContact = model.SkypeContact,
                        Phone        = model.Phone,
                        Email        = model.Email,
                        Id           = WebSecurity.CurrentUserId
                    },
                    Id = WebSecurity.CurrentUserId
                });

                modData.ModifyLecturer();
            }
            else
            {
                var modData = new ModifyStudentViewModel(new Student
                {
                    FirstName  = model.Name,
                    LastName   = model.Surname,
                    MiddleName = model.Patronymic,
                    User       = new User
                    {
                        UserName     = model.UserName,
                        Avatar       = avatar,
                        About        = model.About,
                        SkypeContact = model.SkypeContact,
                        Phone        = model.Phone,
                        Email        = model.Email,
                        Id           = WebSecurity.CurrentUserId
                    },
                    Id = WebSecurity.CurrentUserId
                });

                modData.ModifyStudent();
            }

            return(Json(true));
        }
Ejemplo n.º 2
0
        public ActionResult EditStudent(ModifyStudentViewModel model, int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.ModifyStudent();
                    ViewBag.ResultSuccess = true;
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, string.Empty);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public IActionResult SaveStudent(ModifyStudentViewModel model)
        {
            try
            {
                var user = UsersManagementService.GetUser(model.Id);

                if (user != null)
                {
                    model.ModifyStudent();
                    return(Ok());
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(ServerError500(ex.Message));
            }
        }
Ejemplo n.º 4
0
        public ActionResult EditStudentAjax(ModifyStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = UsersManagementService.GetUserByName(model.Name, model.Surname, model.Patronymic);
                    if (user == null || user.Id == model.Id)
                    {
                        model.ModifyStudent();
                        return(Json(new { resultMessage = "Студент сохранен" }));
                    }

                    ModelState.AddModelError(string.Empty, "Пользователь с таким именем уже существует");
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, string.Empty);
                }
            }

            return(PartialView("_EditStudentView", model));
        }