public IHttpActionResult UpdateEcard(int id, [FromBody] Ecards ecards)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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


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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult AddEcard([FromBody] Ecards ecard)
        {
            //Will Validate according to data annotations specified on model
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Ecards.Add(ecard);
            db.SaveChanges();

            return(Ok(ecard.ecard_id));
        }
        public IHttpActionResult DeleteEcard(int id)
        {
            Ecards ecards = db.Ecards.Find(id);

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

            db.Ecards.Remove(ecards);
            db.SaveChanges();

            return(Ok());
        }
Exemplo n.º 4
0
        public ActionResult Create(Ecards EcardInfo)
        {
            //pass along authentication credential in http request
            GetApplicationCookie();

            //Debug.WriteLine(EcardInfo.EcardMessage);
            //Debug.WriteLine(jss.Serialize(EcardInfo));
            string      url     = "ecardsdata/addecard";
            HttpContent content = new StringContent(jss.Serialize(EcardInfo));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PostAsync(url, content).Result;

            if (response.IsSuccessStatusCode)
            {
                int ecardid = response.Content.ReadAsAsync <int>().Result;
                return(RedirectToAction("Details", new { id = ecardid }));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult FindEcard(int id)
        {
            //Find the data
            Ecards ecard = db.Ecards.Find(id);

            //if not found, return 404 status code.
            if (ecard == null)
            {
                return(NotFound());
            }

            //put into a 'friendly object format'
            EcardsDto EcardsDtos = new EcardsDto
            {
                ecard_id       = ecard.ecard_id,
                photo_path     = ecard.photo_path,
                message        = ecard.message,
                DepartmentName = ecard.Department.DepartmentName
            };


            //pass along data as 200 status code OK response
            return(Ok(EcardsDtos));
        }