Esempio n. 1
0
        // POST api/ProductionOrder
        public HttpResponseMessage PostProductionOrder(ProductionOrder productionorder)
        {
            if (ModelState.IsValid)
            {
                string CustomCode = "ProO-" + DateTime.Now.ToString("yyyyMMdd");

                int? MaxCode = Convert.ToInt32((db.ProductionOrders.Where(r => r.ProductionOrderCode.StartsWith(CustomCode)).Select(r => r.ProductionOrderCode.Substring(CustomCode.Length, 4)).ToList()).Max());
                string ProOCode = CustomCode + ((MaxCode + 1).ToString()).PadLeft(4, '0');
                productionorder.ProductionOrderCode = ProOCode;
                productionorder.Date = DateTime.Now.ToLocalTime();
                productionorder.InsertBy = loginUser.UserID;

                db.ProductionOrders.Add(productionorder);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, productionorder);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = productionorder.ProductionOrderID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 2
0
        // PUT api/ProductionOrder/5
        public HttpResponseMessage PutProductionOrder(long id, ProductionOrder productionorder)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != productionorder.ProductionOrderID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            productionorder.UpdateBy = loginUser.UserID;
            db.Entry(productionorder).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }