Exemplo n.º 1
0
        public IHttpActionResult GetDelegationByUserid(int userid)
        {
            string error = "";
            List <DelegationModel> dm = DelegationRepo.GetDelegationByUserId(userid, out error);

            if (error != "" || dm == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "Requisition Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(dm));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetForAuthenticate()
        {
            var       identity = (ClaimsIdentity)User.Identity;
            UserModel um       = UserRepo.GetUserByUserID(Convert.ToInt32(identity.FindFirst(ClaimTypes.NameIdentifier).Value));

            List <DelegationModel> dm = new List <DelegationModel>();

            dm = DelegationRepo.GetDelegationByUserId(um.Userid, out string error);


            if (dm.Count > 0)
            {
                List <DelegationModel> ActiveDM = dm.Where(x => x.Startdate.Value.Date <= DateTime.Today.Date && x.Enddate.Value.Date >= DateTime.Today.Date && x.Active == ConDelegation.Active.ACTIVE).ToList();
                if (ActiveDM.Count > 0)
                {
                    foreach (DelegationModel d in ActiveDM)
                    {
                        if (um.Role == ConUser.Role.EMPLOYEEREP)
                        {
                            um.Role = ConUser.Role.TEMPHOD;
                            um      = UserRepo.UpdateUser(um);
                        }
                    }
                }
                else
                {
                    List <DelegationModel> InActiveDM = dm.Where(x => x.Enddate.Value.Date < DateTime.Today.Date && x.Active == ConDelegation.Active.ACTIVE).ToList();
                    if (InActiveDM.Count > 0)
                    {
                        foreach (DelegationModel d in InActiveDM)
                        {
                            if (um.Role == ConUser.Role.TEMPHOD)
                            {
                                DelegationRepo.CancelDelegation(d, out error);
                                um = UserRepo.GetUserByUserID(Convert.ToInt32(identity.FindFirst(ClaimTypes.NameIdentifier).Value));
                            }
                        }
                    }
                }
            }



            return(Ok(um));
        }