コード例 #1
0
        public IHttpActionResult PostSupplyRequest([FromBody] SupplyRequestJson supplyRequestJson)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Add Supply Request
            SupplyRequest request = new SupplyRequest()
            {
                tenantId = supplyRequestJson.TenantId,
                active   = true
            };

            db.SupplyRequests.Add(request);

            // Add Supply Request Maps
            foreach (var item in supplyRequestJson.RequestSuppliesMaps)
            {
                RequestSuppliesMap map = new RequestSuppliesMap
                {
                    suppliesRequestId = request.supplyRequestId,
                    supplyId          = item.SupplyId
                };
                db.RequestSuppliesMaps.Add(map);
            }

            db.SaveChanges();
            return(CreatedAtRoute("DefaultApi", new { id = request.supplyRequestId }, request));
        }
コード例 #2
0
        public IHttpActionResult PutRequestSuppliesMap(int id, [FromBody] RequestSuppliesMap requestSuppliesMap)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult PostRequestSuppliesMap([FromBody] RequestSuppliesMap requestSuppliesMap)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RequestSuppliesMaps.Add(requestSuppliesMap);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = requestSuppliesMap.requestSupplyMapId }, requestSuppliesMap));
        }
コード例 #4
0
        public IHttpActionResult DeleteRequestSuppliesMap(int id)
        {
            RequestSuppliesMap requestSuppliesMap = db.RequestSuppliesMaps.Find(id);

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

            db.RequestSuppliesMaps.Remove(requestSuppliesMap);
            db.SaveChanges();

            return(Ok(requestSuppliesMap));
        }
コード例 #5
0
        // Get one basic table
        // DEFAULT CRUD
        public RequestSuppliesMapMapper GetRequestSuppliesMap(int requestSupplyMapId)
        {
            RequestSuppliesMap content = db.RequestSuppliesMaps.FirstOrDefault(j => j.requestSupplyMapId == requestSupplyMapId);

            if (content == null)
            {
                return(null);
            }
            else
            {
                RequestSuppliesMapMapper map = new RequestSuppliesMapMapper()
                {
                    RequestSupplyMapId = content.requestSupplyMapId,
                    SuppliesRequestId  = content.suppliesRequestId ?? default(int),
                    SupplyId           = content.supplyId ?? default(int)
                };
                return(map);
            }
        }