Esempio n. 1
0
 public ActionResult <string> Get(int pId)
 {
     try
     {
         var _company = _groupsConverter.Parse(_groupsService.GetById(pId));
         return(new OkObjectResult(_company));
     }
     catch (ArgumentNullException e)
     {
         return(NotFound(e.Message));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public IActionResult Details(long id)
        {
            var group = _groupsService.GetById(id);

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

            return(View(group.ToViewModel()));
        }
        public async Task <IActionResult> Get(int id)
        {
            var entity = await _GroupsService.GetById(id);

            if (entity == null)
            {
                return(NotFound($"item against this id={id} does not found"));
            }

            return(Ok(entity));
        }
Esempio n. 4
0
        public IActionResult Detalhes(string groupId)
        {
            var model = _groupsService.GetById(Convert.ToInt32(groupId));

            model.EstudanteCheckList = _estudanteService.GetAllEstudante().Select(
                a => new EstudanteCheckBoxListViewModel()
            {
                Id        = a.Id,
                Nome      = a.Nome,
                Selecione = a.GroupsId == Convert.ToInt32(groupId)
            }).ToList();
            return(View(model));
        }
 public Group GetById(long id)
 {
     _logger.LogWarning("######### Helloooooo from {decoratedMethod} #########", nameof(GetById));
     return(_inner.GetById(id));
 }
        public virtual async Task <ActionResult> Create(AddProfessorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (!string.IsNullOrEmpty(viewModel.PNO))
                    {
                        if (_ProfessorService.CheckPNO_Exist(viewModel.PNO))
                        {
                            PopulateGroupsDropDownList(viewModel.Group_Id);
                            ModelState.AddModelError("PNO", "This Professor.NO Is Already Exist In Database");
                            return(View(viewModel));
                        }
                    }
                    var newUser = new User
                    {
                        RegisterType  = UserRegisterType.Active,
                        IsBaned       = false,
                        IP            = Request.ServerVariables["HTTP_X_FORWARDED_FOR"],
                        RegisterDate  = DateTime.Now,
                        LastLoginDate = DateTime.Now,
                        UserName      = viewModel.UserName,
                        Email         = viewModel.Email,
                        Password      = Encryption.EncryptingPassword(viewModel.Password),
                        Role          = _roleService.GetRoleByName("professor"),
                        ProfessorData = new Professor
                        {
                            AvatarPath = viewModel.AvatarPath,
                            BirthDay   = viewModel.BirthDay,
                            Edution    = viewModel.Edution,
                            FirstName  = viewModel.FirstName,
                            Gender     = viewModel.Gender,
                            LastName   = viewModel.LastName,
                            PNO        = viewModel.PNO,
                            Tendency   = viewModel.Tendency,

                            Group = _GroupsService.GetById(viewModel.Group_Id)
                        }
                    };

                    var addUserStatus = _userService.Add(newUser);
                    PopulateGroupsDropDownList(viewModel.Group_Id);
                    if (addUserStatus == AddUserStatus.AddingUserSuccessfully)
                    {
                        await _unitOfWork.SaveChangesAsync();

                        return(RedirectToAction("Index"));
                    }
                    switch (addUserStatus)
                    {
                    case AddUserStatus.EmailExist:
                        ModelState.AddModelError("Email", "This Email Is Already Exist In Database");
                        return(View(viewModel));

                    case AddUserStatus.UserNameExist:
                        ModelState.AddModelError("UserName", "This UserName Is Already Exist In Database");
                        return(View(viewModel));
                    }
                    await _unitOfWork.SaveChangesAsync();

                    CacheManager.InvalidateChildActionsCache();
                    return(RedirectToAction("Index", "Professor"));
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    string s = "";
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        s += String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                           eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            s += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                               ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    ViewBag.err = s;
                }
            }
            PopulateGroupsDropDownList(null);
            return(View(viewModel));
        }