コード例 #1
0
        // PUT: odata/BenthicEventConditions(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <BenthicEventCondition> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BenthicEventCondition benthicEventCondition = db.BenthicEventConditions.Find(key);

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

            BenthicEvent @BenthicEvent = db.BenthicEvents.Find(benthicEventCondition.Id);
            var          check         = AuthorizeLogic.VerifyBenthicEventEditPermission(@BenthicEvent);

            if (check)
            {
                patch.Put(benthicEventCondition);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BenthicEventConditionExists(key))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(Updated(benthicEventCondition));
            }
            else
            {
                return(Unauthorized());
            }
        }
コード例 #2
0
        // POST: odata/BenthicSamples
        public IHttpActionResult Post(BenthicSample benthicSample)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            BenthicEvent @BenthicEvent = db.BenthicEvents.Find(benthicSample.BenthicEventId);
            var check = AuthorizeLogic.VerifyBenthicEventEditPermission(@BenthicEvent);

            if (check)
            {
                db.BenthicSamples.Add(benthicSample);
                db.SaveChanges();

                return Created(benthicSample);
            }
            else
            {
                return Unauthorized();
            }
        }
コード例 #3
0
        // POST: odata/BenthicEvents
        public IHttpActionResult Post(BenthicEvent benthicEvent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var check = AuthorizeLogic.VerifyBenthicEventEditPermission(benthicEvent);

            if (check)
            {
                db.BenthicEvents.Add(benthicEvent);
                db.SaveChanges();

                return(Created(benthicEvent));
            }
            else
            {
                return(Unauthorized());
            }
        }
コード例 #4
0
        public static bool VerifyBenthicEventEditPermission(BenthicEvent benthicEvent)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var id      = HttpContext.Current.User.Identity.GetUserId();
            var context = new ApplicationDbContext();
            //var users = context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains("Volunteer")).ToListAsync();
            var applicationUserManager = new ApplicationUserManger().UserManager;
            var user = applicationUserManager.FindById(id);
            var role = applicationUserManager.GetRoles(user.Id).FirstOrDefault();

            if (role == "Coordinator" | role == "Monitor")
            {
                if (benthicEvent.GroupId == user.GroupId)
                {
                    if (role == "Monitor")
                    {
                        if (benthicEvent.CreatedBy == id)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #5
0
        // DELETE: odata/BenthicSamples(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            BenthicSample benthicSample = db.BenthicSamples.Find(key);
            if (benthicSample == null)
            {
                return NotFound();
            }
            BenthicEvent @BenthicEvent = db.BenthicEvents.Find(benthicSample.BenthicEventId);
            var check = AuthorizeLogic.VerifyBenthicEventEditPermission(@BenthicEvent);

            if (check)
            {
                db.BenthicSamples.Remove(benthicSample);
                db.SaveChanges();

                return StatusCode(HttpStatusCode.NoContent);
            }
            else
            {
                return Unauthorized();
            }
        }