示例#1
0
 public IHttpActionResult Get()
 {
     using (var context = new DataContext())
     {
         BugRepository bugRepository = new BugRepository(context);
         var           bugs          = bugRepository.GetAll();
         var           models        = MapperHelp.Map <ICollection <BugApi> >(bugs);
         return(Ok(models));
     }
 }
 public async Task <History> AddHistory([FromBody] HistoryView history)
 {
     try
     {
         return(await service.Add(MapperHelp.GetHistory(history)));
     }
     catch (CustomException ex)
     {
         return(null);
     }
 }
示例#3
0
 public IHttpActionResult Get(int id)
 {
     using (var context = new DataContext())
     {
         BugRepository  bugRepository  = new BugRepository(context);
         var            bugs           = bugRepository.Find(id);
         UserRepository userRepository = new UserRepository(context);
         bugs.createdby = userRepository.Find(bugs.createdByid);
         if (bugs.modifiedById != null)
         {
             bugs.modifiedBy = userRepository.Find(bugs.modifiedById);
         }
         var models = MapperHelp.Map <BugApi>(bugs);
         return(Ok(models));
     }
 }
示例#4
0
        public IHttpActionResult Post([FromBody] CreateBugApi model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (DataContext dataContext = new DataContext())
            {
                BugRepository bugRepository = new BugRepository(dataContext);
                var           bug           = MapperHelp.Map <Bug>(model);
                bug.createdAt   = DateTime.Now;
                bug.createdByid = CurrentUserId;
                bugRepository.Insert(bug);
                dataContext.SaveChanges();
                var bugApi = MapperHelp.Map <BugApi>(bug);
                return(Ok(bugApi));
            }
        }
示例#5
0
        // PUT: api/Bug/5
        public IHttpActionResult Put(int id, [FromBody] BugApi model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                using (DataContext context = new DataContext())
                {
                    BugRepository bugRepository = new BugRepository(context);
                    var           bug           = MapperHelp.Map <Bug>(model);
                    bug.modifiedAt   = DateTime.Now;
                    bug.modifiedById = CurrentUserId;
                    bugRepository.Update(bug);
                    context.SaveChanges();
                    var bugApi = MapperHelp.Map <BugApi>(bug);
                    return(Ok(bugApi));
                }
            } catch (DbUpdateConcurrencyException ex) {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Conflict, new { Message = "El registro ha sido modificado" })));
            }
        }