Пример #1
0
        public void Topic_ShoulInsertOk()
        {
            var context         = new LearningContext();
            var topicRepository = new TopicRepository(context);

            topicRepository.Insert(new Topic
            {
                Name = "Entity Framework", Descripcion = "Applyling EF6 Data Access Stratagy"
            }
                                   );
            topicRepository.Insert(new Topic
            {
                Name = "Entity Framework2", Descripcion = "Applyling EF6 Data Access Stratagy"
            }
                                   );

            var individual = new IndividualRepository(context);

            individual.Insert(new Individual
            {
                Name = "Benigno", Email = "*****@*****.**"
            }
                              );
            individual.Insert(new Individual
            {
                Name = "Antonio", Email = "*****@*****.**"
            }
                              );
            context.SaveChanges();
        }
Пример #2
0
        public ActionResult Create(TopicViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var repository = new TopicRepository(context);
                    var topicQry   = new Topic {
                        Name = model.Name
                    };
                    var nombreExiste = repository.QueryByExample(topicQry).Count > 0;
                    if (!nombreExiste)
                    {
                        var topic = MapperHelper.Map <Topic>(model);
                        repository.Insert(topic);
                        context.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("Name", "El nombre ya está ocupado por otro tópico.");
                        return(View(model));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View());
            }
        }
Пример #3
0
        internal Guid Create(string title, string content, Guid idCreator)
        {
            Guid idTopic = _topicRepo.Insert(new TopicEntity()
            {
                Title     = title,
                IdCreator = idCreator
            });

            _messageService.Create(idTopic, content, idCreator);

            return(idTopic);
        }
Пример #4
0
        public async Task <TopicDto> CreateTopic(string topicName)
        {
            if (topicName.Contains(","))
            {
                throw new FormInvalidException("", "Topic name cannot contain ','");
            }

            var topic = new Topic {
                TopicName = topicName
            };

            topic = await _repository.Insert(topic);

            return(_mapper.Map <TopicDto>(topic));
        }
Пример #5
0
 public void Topic_ShouldInsertOK()
 {
     try
     {
         var context         = new LearningContext();
         var topicRepository = new TopicRepository(context);
         topicRepository.Insert(new Topic {
             Name = "Entity Framework ", Description = "Applying EF6 Data Access Strategy"
         });
         context.SaveChanges();
         Assert.IsFalse(false);
     }
     catch (Exception ex) {
         Assert.IsFalse(true);
     }
 }
Пример #6
0
        public void Topic_ShouldInsertOk()
        {
            //
            // TODO: Agregar aquí la lógica de las pruebas
            //
            var context = new LearningContext();

            var topicRepository = new TopicRepository(context);

            topicRepository.Insert(new Topic {
                Name        = "Entity Framework",
                Description = "Applying EF6 Data Acces Strategy"
            });

            context.SaveChanges();
        }
Пример #7
0
        public IHttpActionResult Post([FromBody] BlogTopic blogTopic)
        {
            if (!IsUserAdmin())
            {
                // If user isn't admin
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized)));
            }

            if (!ModelState.IsValid)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)));
            }

            try
            {
                ITopicRepository topicRepository = new TopicRepository();
                topicRepository.Insert(blogTopic);
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Created, blogTopic)));
            }
            catch
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, "Failed To Create")));
            }
        }