public ActionResult <Work> EditMyFacilityWorker(int facilityID, int workID, string position, bool?isAdmin)
        {
            User user = UserRep.FindByEmail(User.Identity.Name);
            Work work = WorkRep.Find(workID);


            if (work.FacilityID != facilityID)
            {
                return(new ForbidResult());
            }
            else if (FacilityRep.IsAdmin(user, work.Facility))
            {
                if (position != null)
                {
                    work.Position = position;
                }
                if (isAdmin != null)
                {
                    work.IsAdmin = (bool)isAdmin;
                }
                DbContext.SaveChanges();
                return(Ok(work));
            }
            else
            {
                return(new ForbidResult());
            }
        }
Ejemplo n.º 2
0
        public ActionResult DeleteWork(int workID)
        {
            User user = UserRep.FindByEmail(User.Identity.Name);

            if (user != WorkRep.Find(workID).User)
            {
                return(Forbid());
            }
            else if (UserRep.DeleteWork(user, workID))
            {
                return(Ok());
            }
            else
            {
                return(StatusCode(500, "Internal Server Error. Somthing went Wrong!"));
            }
        }