Exemple #1
0
        public ActionResult EditArea(TopicAreaDTO model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!TopicAreaService.AreaExists(model.Description, model.TopicAreaId))
                    {
                        TopicAreaService.EditThisArea(model);
                        return(RedirectToAction("ControlPanel", "Administrator"));
                    }
                    else
                    {
                        ModelState.AddModelError("Description", "- La área temática escrita ya existe.");
                        return(View(model));
                    }
                }

                return(View(model));
            }
            catch
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError));
            }
        }
Exemple #2
0
        public ActionResult CreateArea(TopicAreaDTO model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!TopicAreaService.AreaExists(model.Description))
                    {
                        TopicAreaService.CreateNewArea(model);
                        return(RedirectToAction("ControlPanel", "Administrator"));
                    }
                    else
                    {
                        ModelState.AddModelError("Description", "- El área especificada ya existe.");
                        return(View(model));
                    }
                }

                throw new Exception();
            }
            catch
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError));
            }
        }
Exemple #3
0
        public void EditThisArea(TopicAreaDTO model)
        {
            using (var context = new ApplicationDbContext())
            {
                TopicArea topicAreaToEdit = context.TopicAreas.FirstOrDefault(x => x.TopicAreaId == model.TopicAreaId);
                topicAreaToEdit.Description = model.Description;

                context.SaveChanges();
            }
        }
Exemple #4
0
 public void CreateNewArea(TopicAreaDTO model)
 {
     using (var context = new ApplicationDbContext())
     {
         TopicArea topicArea = new TopicArea();
         topicArea.TopicAreaId = context.TopicAreas.Count() + 1;
         topicArea.Description = model.Description;
         context.TopicAreas.Add(topicArea);
         context.SaveChanges();
     }
 }
Exemple #5
0
        public TopicAreaDTO GetTopicAreaById(int id)
        {
            using (var context = new ApplicationDbContext())
            {
                TopicAreaDTO topicAreaDto = new TopicAreaDTO();
                var          topicAreaDB  = context.TopicAreas.FirstOrDefault(x => x.TopicAreaId == id);
                topicAreaDto.TopicAreaId = topicAreaDB.TopicAreaId;
                topicAreaDto.Description = topicAreaDB.Description;

                return(topicAreaDto);
            }
        }