Пример #1
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            EditEcard ViewModel = new EditEcard();

            string url = "ecardsdara/findecard" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);

            if (response.IsSuccessStatusCode)
            {
                //Put data into contact data transfer object
                EcardsDto SelectedEcards = response.Content.ReadAsAsync <EcardsDto>().Result;
                ViewModel.ecards = SelectedEcards;

                //get information about departments this ecard belongs to.
                url      = "departmentsdata/getdepartments";
                response = client.GetAsync(url).Result;
                IEnumerable <DepartmentsDto> PotentialContact = response.Content.ReadAsAsync <IEnumerable <DepartmentsDto> >().Result;
                ViewModel.alldepartments = PotentialContact;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Пример #2
0
        // GET: Ecards/Details/{key}
        public ActionResult Details(int id)
        {
            ShowEcard ViewModel = new ShowEcard();

            //Pass along to the view information about who is logged in
            ViewModel.isadmin = User.IsInRole("Admin");



            string url = "ecardsdata/findecard/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into ecard data transfer object
                EcardsDto SelectedEcard = response.Content.ReadAsAsync <EcardsDto>().Result;
                ViewModel.ecard = SelectedEcard;


                url      = "ecardsdata/finddepartmentforecard/" + id;
                response = client.GetAsync(url).Result;
                DepartmentsDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentsDto>().Result;
                ViewModel.departments = SelectedDepartment;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Пример #3
0
        public ActionResult DeleteConfirm(int id)
        {
            string url = "ecardsdata/findecard/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into contact data transfer object
                EcardsDto SelectedEcard = response.Content.ReadAsAsync <EcardsDto>().Result;
                return(View(SelectedEcard));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult GetEcards()
        {
            List <Ecards>    Ecards     = db.Ecards.ToList();
            List <EcardsDto> EcardsDtos = new List <EcardsDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Ecard in Ecards)
            {
                EcardsDto NewEcard = new EcardsDto
                {
                    ecard_id       = Ecard.ecard_id,
                    photo_path     = Ecard.photo_path,
                    message        = Ecard.message,
                    DepartmentName = Ecard.Department.DepartmentName
                };
                EcardsDtos.Add(NewEcard);
            }

            return(Ok(EcardsDtos));
        }
        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));
        }