public IHttpActionResult PutMunitionsInventory(string id, MunitionsInventory munitionsInventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetMunitionsInventory(string id)
        {
            MunitionsInventory munitionsInventory = db.MunitionsInventory.Find(id);

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

            return(Ok(munitionsInventory));
        }
        public IHttpActionResult DeleteMunitionsInventory(string id)
        {
            MunitionsInventory munitionsInventory = db.MunitionsInventory.Find(id);

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

            db.MunitionsInventory.Remove(munitionsInventory);
            db.SaveChanges();

            return(Ok(munitionsInventory));
        }
        public IHttpActionResult PostMunitionsInventory(MunitionsInventory munitionsInventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            munitionsInventory.id               = Guid.NewGuid().ToString();
            munitionsInventory.lastUpdate       = DateTime.Now;
            munitionsInventory.lastUpdateUserId = "000";

            db.MunitionsInventory.Add(munitionsInventory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MunitionsInventoryExists(munitionsInventory.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            db.MunitionStatus.Add(new MunitionStatu
            {
                MunitionInventoryID = munitionsInventory.id,
                StatusCode          = (int)AssetStatuses.FLIGHT_READY,
                ETIC             = DateTime.Now.Add(new TimeSpan(90, 0, 0, 0)),
                lastUpdate       = DateTime.Now,
                lastUpdateUserId = "000"
            });

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(CreatedAtRoute("DefaultApi", new { id = munitionsInventory.id }, munitionsInventory));
        }
        public IHttpActionResult PostMunitionsInventory(MunitionsInventory munitionsInventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (db.Munitions.Where(x => x.MunitionID == munitionsInventory.metaDataID).Count() <= 0)
            {
                return(BadRequest("Invalid Munition Specifications ID (metaDataID)"));
            }

            if (db.Locations.Where(x => x.LocationID == munitionsInventory.locationID).Count() <= 0)
            {
                return(BadRequest("Invalid Location ID"));
            }

            if (db.Units.Where(x => x.id == munitionsInventory.owningUnit).Count() <= 0)
            {
                return(BadRequest("Invalid Owning Unit ID"));
            }

            if (munitionsInventory.serialNumber != null && munitionsInventory.serialNumber.Length > 50)
            {
                return(BadRequest("Serial Number is too long"));
            }

            if (munitionsInventory.branch != null)
            {
                if (!db.BranchOfServices.Any(x => x.id == munitionsInventory.branch))
                {
                    return(BadRequest("Invalid Branch"));
                }
            }

            if (munitionsInventory.COCOM != null)
            {
                if (!db.COCOMs.Any(x => x.id == munitionsInventory.COCOM))
                {
                    return(BadRequest("Invalid COCOM"));
                }
            }

            munitionsInventory.id               = Guid.NewGuid().ToString();
            munitionsInventory.lastUpdate       = DateTime.Now;
            munitionsInventory.lastUpdateUserId = "000";

            db.MunitionsInventory.Add(munitionsInventory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MunitionsInventoryExists(munitionsInventory.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            db.MunitionStatus.Add(new MunitionStatu
            {
                MunitionInventoryID = munitionsInventory.id,
                StatusCode          = (int)AssetStatuses.FLIGHT_READY,
                ETIC             = 0,
                lastUpdate       = DateTime.Now,
                lastUpdateUserId = "000"
            });

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(CreatedAtRoute("DefaultApiPost", new { id = munitionsInventory.id }, munitionsInventory));
        }
        public IHttpActionResult PutMunitionsInventory(string id, MunitionsInventory munitionsInventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            if (db.Munitions.Where(x => x.MunitionID == munitionsInventory.metaDataID).Count() <= 0)
            {
                return(BadRequest("Invalid Munition Specifications ID (metaDataID)"));
            }

            if (db.Locations.Where(x => x.LocationID == munitionsInventory.locationID).Count() <= 0)
            {
                return(BadRequest("Invalid Location ID"));
            }

            if (db.Units.Where(x => x.id == munitionsInventory.owningUnit).Count() <= 0)
            {
                return(BadRequest("Invalid Owning Unit ID"));
            }

            if (munitionsInventory.serialNumber != null && munitionsInventory.serialNumber.Length > 50)
            {
                return(BadRequest("Serial Number is too long"));
            }

            if (munitionsInventory.branch != null)
            {
                if (!db.BranchOfServices.Any(x => x.id == munitionsInventory.branch))
                {
                    return(BadRequest("Invalid Branch"));
                }
            }

            if (munitionsInventory.COCOM != null)
            {
                if (!db.COCOMs.Any(x => x.id == munitionsInventory.COCOM))
                {
                    return(BadRequest("Invalid COCOM"));
                }
            }

            munitionsInventory.lastUpdate       = DateTime.Now;
            munitionsInventory.lastUpdateUserId = "000";

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }