public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] BodySystem bodySystem)
        {
            if (id != bodySystem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await this.bodySystemsService.ModifyAsync(bodySystem.Id, bodySystem.Name);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (this.bodySystemsService.GetById <BodySystem>(id) == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw new Exception("A problem occurred while trying to edit this body system.");
                    }
                }

                this.TempData["ModifiedBodySystem"] = $"You have successfully modified {bodySystem.Name}!";

                return(this.RedirectToAction("Index"));
            }

            return(View(bodySystem));
        }
        public IHttpActionResult PutBodySystem(int id, BodySystem bodySystem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bodySystem.BodySystemId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetBodySystem(int id)
        {
            BodySystem bodySystem = db.BodySystems.Find(id);

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

            return(Ok(bodySystem));
        }
Пример #4
0
        public async Task <int> CreateAsync(string name)
        {
            var bodySystem = new BodySystem {
                Name = name
            };

            await this.bodySystemsRepository.AddAsync(bodySystem);

            await this.bodySystemsRepository.SaveChangesAsync();

            return(bodySystem.Id);
        }
        public IHttpActionResult PostBodySystem(BodySystem bodySystem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.BodySystems.Add(bodySystem);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = bodySystem.BodySystemId }, bodySystem));
        }
        public IHttpActionResult DeleteBodySystem(int id)
        {
            BodySystem bodySystem = db.BodySystems.Find(id);

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

            db.BodySystems.Remove(bodySystem);
            db.SaveChanges();

            return(Ok(bodySystem));
        }