Beispiel #1
0
        public IHttpActionResult PostPoMaster(PoMaster poMaster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PoMasters.Add(poMaster);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (PoMasterExists(poMaster.PoNo))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = poMaster.PoNo }, poMaster));
        }
Beispiel #2
0
        // GET: POMASTERs/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PoMaster pOMASTER = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                //HTTP GET
                var responseTask = client.GetAsync("POMASTERs/" + id);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <PoMaster>();
                    readTask.Wait();

                    pOMASTER = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            if (pOMASTER == null)
            {
                return(HttpNotFound());
            }
            return(View(pOMASTER));
        }
Beispiel #3
0
        // GET: POMASTERs/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PoMaster pOMASTER = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                //HTTP GET
                var responseTask = client.GetAsync("POMASTERs/" + id);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <PoMaster>();
                    readTask.Wait();

                    pOMASTER = readTask.Result;
                }
            }
            if (pOMASTER == null)
            {
                return(HttpNotFound());
            }


            ViewBag.SUPLNO = new SelectList(GetSuppliers(), "SUPLNO", "SUPLNAME", pOMASTER.SUPLNO);
            return(View(pOMASTER));
        }
Beispiel #4
0
        public IHttpActionResult PutPoMaster(string id, PoMaster poMaster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #5
0
        public IHttpActionResult GetPoMaster(string id)
        {
            PoMaster poMaster = db.PoMasters.Find(id);

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

            return(Ok(poMaster));
        }
Beispiel #6
0
        public async Task <bool> Edit(PoVM povm)
        {
            PoMaster poMaster = mapper.Map <PoMaster>(povm);

            foreach (var detail in poMaster.Details)
            {
                detail.PuchaseOrderNumber  = poMaster.PoNumber;
                detail.PurchaseOrderMaster = poMaster;
            }
            return((await poRepo.EditPo(poMaster) != null) ? true : false);
        }
Beispiel #7
0
        public IHttpActionResult DeletePoMaster(string id)
        {
            PoMaster poMaster = db.PoMasters.Find(id);

            if (poMaster == null)
            {
                return(NotFound());
            }
            db.PoDetails.RemoveRange(poMaster.PoDetails);
            db.PoMasters.Remove(poMaster);
            db.SaveChanges();

            return(Ok(poMaster));
        }
        public ActionResult DeletePurhcaseDetail(string id, string itcode)
        {
            var client   = new HttpClient();
            var response = client.GetAsync("http://localhost:50788/api/PoDetails?id=" + id + "&itcode=" + itcode).Result;
            var poDetail = response.Content.ReadAsAsync <PoDetail>().Result;

            response = client.GetAsync("http://localhost:50788/api/Items/" + itcode).Result;
            Item item = response.Content.ReadAsAsync <Item>().Result;

            poDetail.Item = item;
            response      = client.GetAsync("http://localhost:50788/api/PoMasters/" + id).Result;
            PoMaster poMasters = response.Content.ReadAsAsync <PoMaster>().Result;

            poDetail.PoMaster = poMasters;
            return(View(poDetail));
        }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "PONO,PODATE,SUPLNO")] PoMaster poMaster)
 {
     if (ModelState.IsValid)
     {
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri(apiUrl + "POMASTERs / " + poMaster.PONO);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = client.PutAsJsonAsync(poMaster.PONO, poMaster).Result;
             if (response.IsSuccessStatusCode)
             {
                 return(RedirectToAction("Index"));
             }
         }
     }
     ViewBag.SUPLNO = new SelectList(GetSuppliers(), "SUPLNO", "SUPLNAME", poMaster.SUPLNO);
     return(View(poMaster));
 }
        public ActionResult AddPurchase()
        {
            ViewBag.Message = "Make new purchase.";
            var      client    = new HttpClient();
            var      response  = client.GetAsync("http://localhost:50788/api/Suppliers").Result;
            var      suppliers = response.Content.ReadAsAsync <IEnumerable <Supplier> >().Result;
            PoMaster master    = new PoMaster();
            List <SelectListItem> supplierList = new List <SelectListItem>();

            foreach (Supplier sup in suppliers.ToList())
            {
                supplierList.Add(new SelectListItem
                {
                    Text  = sup.SuplName,
                    Value = sup.SuplNo
                });
            }
            master.Suppliers = supplierList;
            return(View(master));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "PONO,PODATE,SUPLNO")] PoMaster poMaster)
        {
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(apiUrl);

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <PoMaster>("POMASTERs", poMaster);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }

            ViewBag.SUPLNO = new SelectList(GetSuppliers(), "SUPLNO", "SUPLNAME", poMaster.SUPLNO);
            return(View(poMaster));
        }
Beispiel #12
0
        public async Task <bool> Add(PoVM povm)
        {
            PoMaster poMaster = mapper.Map <PoMaster>(povm);

            return(await poRepo.AddPo(poMaster));
        }