예제 #1
0
        public ActionResult Edit(int id)
        {
            var projection = _uploadReferencebooksService.GetReferencebooksById(id);

            var classResult   = _apiService.GetClasses();
            var classes       = JsonConvert.DeserializeObject <List <ClassProjection> >(classResult);
            var boardResult   = _apiService.GetBoards();
            var boards        = JsonConvert.DeserializeObject <List <BoardProjection> >(boardResult);
            var classId       = classes.Where(x => x.Name == projection.ClassName).Select(y => y.ClassId).FirstOrDefault();
            var subjectResult = _apiService.GetSubjects(classId);
            var subjects      = JsonConvert.DeserializeObject <List <SubjectProjection> >(subjectResult);
            var boardId       = boards.Where(x => x.Name == projection.BoardName).Select(y => y.BoardId).FirstOrDefault();
            var subjectId     = subjects.Where(x => x.Name == projection.SubjectName).Select(y => y.SubjectId).FirstOrDefault();

            ViewBag.classList = (from b in classes
                                 select new SelectListItem
            {
                Value = b.ClassId.ToString(),
                Text = b.Name
            }).ToList();

            ViewBag.boardList = (from b in boards
                                 select new SelectListItem
            {
                Value = b.BoardId.ToString(),
                Text = b.Name
            }).ToList();

            ViewBag.subjectList = (from b in subjects
                                   select new SelectListItem
            {
                Value = b.SubjectId.ToString(),
                Text = b.Name
            }).ToList();

            if (projection == null)
            {
                _logger.Warn(string.Format("Referencebooks does not Exists {0}."));
                Warning("Referencebooks does not Exists.");
                return(RedirectToAction("Index"));
            }

            var viewModel = AutoMapper.Mapper.Map <UploadReferencebooksProjection, UploadReferencebooksEditViewModel>(projection);

            ViewBag.ClassId   = classId;
            ViewBag.BoardId   = boardId;
            ViewBag.SubjectId = subjectId;

            return(View(viewModel));
        }
        public HttpResponseMessage GetReferencebooksById(int id)
        {
            var Referencebooks = _uploadReferencebooksService.GetReferencebooksById(id);

            return(Request.CreateResponse(HttpStatusCode.OK, Referencebooks));
        }