示例#1
0
 public bool AddRecord(ref OutputPortView record)
 {
     try
     {
         var newRecord = Mapper.Map<OutputPort>(record);
         _deviceContext.OutputPorts.Add(newRecord);
         _deviceContext.SaveChanges();
         record = Mapper.Map<OutputPortView>(newRecord);
         return true;
     }
     catch (Exception e)
     {
         LogTo.Fatal("Database insert failed.\r\n Error Message :" + e.Message);
         return false;
     }
 }
 public ActionResult OutputPortsCreate(OutputPortView outputPortView)
 {
     if (outputPortView == null)
         return Json(new
         {
             Result = "ERROR",
             Message = "We tried hard but beyond control\r\n " +
                       "Please try later"
         });
     try
     {
         if (!ModelState.IsValid)
         {
             return Json(new
             {
                 Result = "ERROR",
                 Message = "Form is not valid! "
             });
         }
         if (_outPortRules.AddRecord(ref outputPortView))
             return Json(new
             {
                 Result = "OK",
                 Record = outputPortView
             });
         return Json(new
         {
             Result = "ERROR",
             Message = "We tried hard but beyond control\r\n " +
                       "Please try later"
         });
     }
     catch (Exception exception)
     {
         LogTo.Fatal("{0}{1}", _exceptionMessage, exception.Message);
         return Json(new
         {
             Result = "ERROR",
             Message = "We tried hard but beyond control\r\n " +
                       "Please try later"
         });
     }
 }
        public ActionResult OutputPortsUpdate(OutputPortView outputPortView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.GetEnumerator();
                    var message = errors.ToNullSafeString();

                    return Json(new
                    {
                        Result = "ERROR",
                        Message = "Form is not valid! Error " +
                                  message
                    });
                }
                _outPortRules.UpdateRecord(ref outputPortView);
                return Json(new
                {
                    Result = "OK",
                    Record = outputPortView
                });
            }
            catch (Exception e)
            {
                LogTo.Fatal("Error while adding record \r\nMessage:" +
                    e.Message);
                return Json(new
                {
                    Result = "ERROR",
                    Message = "Error while editing record" +
                              "Please try later"
                });
            }
        }
示例#4
0
 public bool UpdateRecord(ref OutputPortView record)
 {
     var outputs = _deviceContext.OutputPorts.Find(record.Id);
     if (outputs == null) return false;
     record.Device = outputs.Device;
     Mapper.Map(record, outputs);
     try
     {
         _deviceContext.SaveChanges();
         Mapper.Map(record, outputs);
         return true;
     }
     catch (Exception exception)
     {
         LogTo.Fatal("Error while updating record\r\n Message: ");
         LogTo.Fatal(exception.Message);
         return false; ;
     }
 }