public CarEngineWithGearboxModel(int id, int modelId, CarEngineModel engine, GearboxModel gearbox, int price) : base(id)
 {
     ModelId = modelId;
     Engine  = engine;
     Gearbox = gearbox;
     Price   = price;
 }
Пример #2
0
        public async Task <IHttpActionResult> PutGearboxModel(Guid id, GearboxModel gearboxModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IHttpActionResult> GetGearboxModel(Guid id)
        {
            GearboxModel gearboxModel = await db.GearboxModels.FindAsync(id);

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

            return(Ok(gearboxModel));
        }
Пример #4
0
        public async Task <IHttpActionResult> PostGearboxModel(GearboxModel gearboxModel)
        {
            int writeLevel = Util.GetResourcePermission("Master Data", Util.ReourceOperations.Write);

            if (writeLevel != 2)
            {
                ModelState.AddModelError("Access Level", "Unauthorized create access.");
            }

            var em = db.GearboxModels.Where(m => m.Name == gearboxModel.Name).FirstOrDefault();

            if (em != null)
            {
                ModelState.AddModelError("Duplicate", "Gearbox model already existed.");
            }

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

            db.GearboxModels.Add(gearboxModel);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (GearboxModelExists(gearboxModel.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = gearboxModel.Id }, gearboxModel));
        }
Пример #5
0
        public async Task <IHttpActionResult> DeleteGearboxModel(Guid id)
        {
            int deleteLevel = Util.GetResourcePermission("Master Data", Util.ReourceOperations.Delete);

            if (deleteLevel != 2)
            {
                ModelState.AddModelError("Access Level", "Unauthorized delete access.");
            }

            GearboxModel gearboxModel = await db.GearboxModels.FindAsync(id);

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

            db.GearboxModels.Remove(gearboxModel);
            await db.SaveChangesAsync();

            return(Ok(gearboxModel));
        }
        public async Task <IHttpActionResult> PutGearboxModel(Guid id, GearboxModel gearboxModel)
        {
            int writeLevel = Util.GetResourcePermission("Master Data", Util.ReourceOperations.Write);

            if (writeLevel != 2)
            {
                ModelState.AddModelError("Access Level", "Unauthorized write access.");
            }

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

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }