Пример #1
0
        public IHttpActionResult Post([FromBody] SRSessionNewViewModel session)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var exist = _issrepo.GetAll().FirstOrDefault(x => x.SessionID == session.SessionID);
                    if (exist == null)
                    {
                        var newSession = Mapper.Map <SRSession>(session);
                        newSession.EnteredBy     = User.Identity.Name;
                        newSession.AuditDateTime = DateTime.Now;
                        //Save to database
                        _issrepo.Insert(newSession);
                        _issrepo.Save();
                        return(Json(new { success = true }));
                    }
                }
            }
            catch (DbEntityValidationException dbex)
            {
                return(Json(new { Message = ValidationErrorMsg(dbex) }));
            }

            // Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { data = GetErrorMessages().ToList() }));
        }
Пример #2
0
 public IHttpActionResult EditSession([FromBody] SRSessionNewViewModel session)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var currentRecord = _issrepo.GetAll().FirstOrDefault(x => x.RecordID == session.RecordID);
             if (currentRecord != null)
             {
                 currentRecord.EnteredBy = User.Identity.Name;
             }
             //Save to database
             _issrepo.Edit2(currentRecord, session);
             _issrepo.Save();
             return(Json(new { success = true }));
         }
     }
     catch (DbEntityValidationException dbex)
     {
         return(Json(new { Message = ValidationErrorMsg(dbex) }));
     }
     return(Json(new { Message = "Failed", ModelState = ModelState }));
 }