Beispiel #1
0
 public int AddUpdateAudit(AuditViewModel auditViewModel)
 {
     if (auditViewModel.Id == 0)
         return AddAudit(auditViewModel);
     else
         return UpdateAudit(auditViewModel);
 }
Beispiel #2
0
 public int AddAudit(AuditViewModel auditViewModel)
 {
     var localDateTime = GetNZLocalTime();
     var entity = new Audit();
     entity.Comments = auditViewModel.Comments;
     entity.Status = auditViewModel.Status;
     entity.LastModifiedOn = localDateTime;
     var x = db.Audits.Add(entity);
     db.SaveChanges();
     return x.Id;
 }
Beispiel #3
0
        public IHttpActionResult PostAudit(AuditViewModel audit)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var r = _auditService.AddUpdateAudit(audit);

            return CreatedAtRoute("DefaultApi", new { id = r }, audit);

            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //db.Audits.Add(audit);
            //db.SaveChanges();

            //return CreatedAtRoute("DefaultApi", new { id = audit.Id }, audit);
        }
Beispiel #4
0
        public IHttpActionResult PutAudit(int id, AuditViewModel audit)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //if (id != audit.Id)
            //{
            //    return BadRequest();
            //}

            //db.Entry(audit).State = EntityState.Modified;

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!AuditExists(id))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            //return StatusCode(HttpStatusCode.NoContent);

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != audit.Id)
            {
                return BadRequest();
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var r = _auditService.AddUpdateAudit(audit);
                return Ok(r);
            }
            catch (Exception e)
            {
                return StatusCode(HttpStatusCode.NoContent);
            }
        }
Beispiel #5
0
 public int UpdateAudit(AuditViewModel auditViewModel)
 {
     var localDateTime = GetNZLocalTime();
     var entity = db.Audits.SingleOrDefault(b => b.Id == auditViewModel.Id);
     if (entity != null)
     {
         entity.Comments = auditViewModel.Comments;
         entity.Status = auditViewModel.Status;
         entity.LastModifiedOn = localDateTime;
         db.SaveChanges();
     }
     return entity.Id;
 }