Exemple #1
0
        public IHttpActionResult PutPRILOG(int id, PRILOG pRILOG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <ActionResult> Edit(int id, PRILOG Emp)
        {
            HttpResponseMessage responseMessage = await client.PutAsJsonAsync(url + "/" + id, Emp);

            if (responseMessage.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Error"));
        }
        public async Task <ActionResult> Create(PRILOG tipGlasa)
        {
            HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, tipGlasa);

            if (responseMessage.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Error"));
        }
        public async Task <ActionResult> Delete(int id, PRILOG tipGlasa)
        {
            HttpResponseMessage responseMessage = await client.DeleteAsync(url + "/" + id);

            if (responseMessage.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Error"));
        }
Exemple #5
0
        public IHttpActionResult DeletePRILOG(int id)
        {
            PRILOG pRILOG = db.PRILOG.Find(id);

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

            db.PRILOG.Remove(pRILOG);
            db.SaveChanges();

            return(Ok(pRILOG));
        }
Exemple #6
0
        public IHttpActionResult GetPRILOG(int id)
        {
            PRILOG pRILOG = db.PRILOG.Find(id);

            if (pRILOG == null)
            {
                return(NotFound());
            }
            PrilogDTO model = new PrilogDTO()
            {
                ContentType = pRILOG.CONTENT_TYPE,
                Id          = pRILOG.ID,
                Naziv       = pRILOG.NAZIV
            };



            return(Ok(model));
        }
Exemple #7
0
        public async Task <HttpResponseMessage> PostPRILOG()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            //var prilog = await Request.Content.ReadAsAsync<PrilogDTO>();

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                PRILOG model = new PRILOG()
                {
                    NAZIV        = provider.FormData.Get("naziv"),
                    CONTENT_TYPE = provider.FileData[0].Headers.ContentType.MediaType,
                    SADRZAJ      = File.ReadAllBytes(provider.FileData[0].LocalFileName),
                    SJEDNICA     = db.SJEDNICA.Find(Convert.ToInt32(provider.FormData.Get("sjednicaid")))
                };

                db.PRILOG.Add(model);
                db.SaveChanges();
                File.Delete(provider.FileData[0].LocalFileName);
                //  model.SADRZAJ = null;
                // GetPRILOG(model.ID);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }