public IHttpActionResult Post([FromBody] ReportRejection reason)
        {
            try
            {
                if (reason == null)
                {
                    return(BadRequest());
                }



                var result = _repository.Insert(reason);
                if (result.Status == RepositoryActionStatus.Created)
                {
                    // map to dto
                    return(Created <ReportRejection>(Request.RequestUri
                                                     + "/" + reason.Id.ToString(), reason));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Exemple #2
0
        public RepositoryActionResult <ReportRejection> Update(ReportRejection t)
        {
            try
            {
                var existingData = _ctx.ReportRejections.FirstOrDefault(exp => exp.Id == t.Id);

                if (existingData == null)
                {
                    return(new RepositoryActionResult <ReportRejection>(t, RepositoryActionStatus.NotFound));
                }

                _ctx.Entry(existingData).State = EntityState.Detached;
                _ctx.ReportRejections.Attach(t);
                _ctx.Entry(t).State = EntityState.Modified;


                var result = _ctx.SaveChanges();
                if (result > 0)
                {
                    return(new RepositoryActionResult <ReportRejection>(t, RepositoryActionStatus.Updated));
                }
                else
                {
                    return(new RepositoryActionResult <ReportRejection>(t, RepositoryActionStatus.NothingModified, null));
                }
            }
            catch (Exception ex)
            {
                return(new RepositoryActionResult <ReportRejection>(null, RepositoryActionStatus.Error, ex));
            }
        }
        public async Task <ActionResult> RejectReport(ReportRejection model)
        {
            model.DateCreated = DateTime.UtcNow;
            if (ModelState.IsValid)
            {
                _applicationDbContext.ReportRejections.Add(model);
                await _applicationDbContext.SaveChangesAsync();

                var ReportToUpdate = _applicationDbContext.Reports.SingleOrDefault(id => id.ReportId == model.ReportId);
                ReportToUpdate.RejectionStatus = true;

                _applicationDbContext.Entry(ReportToUpdate).State = EntityState.Modified;
                await _applicationDbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Unable to add request");
            return(View());
        }
Exemple #4
0
 public RepositoryActionResult <ReportRejection> Insert(ReportRejection t)
 {
     try
     {
         _ctx.ReportRejections.Add(t);
         var result = _ctx.SaveChanges();
         if (result > 0)
         {
             return(new RepositoryActionResult <ReportRejection>(t, RepositoryActionStatus.Created));
         }
         else
         {
             return(new RepositoryActionResult <ReportRejection>(t, RepositoryActionStatus.NothingModified, null));
         }
     }
     catch (Exception ex)
     {
         return(new RepositoryActionResult <ReportRejection>(null, RepositoryActionStatus.Error, ex));
     }
 }