public IHttpActionResult PutApprentice(int id, Apprentice apprentice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != apprentice.Id)
            {
                return(BadRequest());
            }

            db.Entry(apprentice).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task <IActionResult> PutSession(int id, Session session)
        {
            if (id != session.ID)
            {
                return(BadRequest());
            }

            _context.Entry(session).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SessionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutInvoice(int id, Invoice invoice)
        {
            try
            {
                // Getting and checking that CabinOwner owns the Cabin what is in Invoice
                if (User.IsInRole("CabinOwner"))
                {
                    var cabinReservation = await _context.CabinReservation.Where(cabinReservation => cabinReservation.Cabin.Person.Email == User.Identity.Name).FirstOrDefaultAsync();

                    if (cabinReservation == null)
                    {
                        return(Unauthorized());
                    }
                }

                if (id != invoice.InvoiceId)
                {
                    return(BadRequest());
                }

                _context.Entry(invoice).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch
            {
                return(StatusCode(500));
            }
        }
예제 #5
0
        public async Task <IActionResult> PutPerson(int id, Person person)
        {
            try
            {
                // Checks that User-role is Administrator or User in IdentityDB matches Person in CabinReservationsDB
                if (false == User.IsInRole("Administrator") && person.Email != User.Identity.Name)
                {
                    return(Unauthorized());
                }

                if (id != person.PersonId)
                {
                    return(BadRequest());
                }

                _context.Entry(person).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(NoContent());
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
예제 #6
0
        public async Task <IActionResult> PutResort(int id, [FromBody] Resort resort)
        {
            if (id != resort.ResortId)
            {
                return(BadRequest());
            }

            _context.Entry(resort).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResortExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> PutActivity(int id, Activity activity)
        {
            if (id != activity.ActivityId)
            {
                return(BadRequest());
            }

            _context.Entry(activity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ActivityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #8
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }
            Product original = await _context.Product.AsNoTracking <Product>().FirstOrDefaultAsync(p => p.Id == id);

            AuthorizationResult authresult = await _authorizationService.AuthorizeAsync(User, original, "ProductOwner");

            if (!authresult.Succeeded)
            {
                if (User.Identity.IsAuthenticated)
                {
                    return(new ForbidResult());
                }
                else
                {
                    return(new ChallengeResult());
                }
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }