示例#1
0
 public bool AddRecord(ref InputPortView record)
 {
     try
     {
         var newRecord = Mapper.Map<InputPort>(record);
         _deviceContext.InputPorts.Add(newRecord);
         _deviceContext.SaveChanges();
         record = Mapper.Map<InputPortView>(newRecord);
         return true;
     }
     catch (Exception e)
     {
         LogTo.Fatal("Database insert failed.\r\n Error Message :" + e.Message);
         return false;
     }
 }
 public ActionResult InputPortsCreate(InputPortView inputPortView)
 {
     if (inputPortView == 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 (_iPortRules.AddRecord(ref inputPortView))
             return Json(new
             {
                 Result = "OK",
                 Record = inputPortView
             });
         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"
         });
     }
 }
        /// <summary>
        /// Inputs the ports update.
        /// </summary>
        /// <param name="inputPortView">The input port view.</param>
        /// <returns></returns>
        public ActionResult InputPortsUpdate(InputPortView inputPortView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.GetEnumerator();
                    var message = errors.ToNullSafeString();

                    return Json(new
                    {
                        Result = "ERROR",
                        Message = "Form is not valid! Error " +
                                  message
                    });
                }
                _iPortRules.UpdateRecord(ref inputPortView);
                return Json(new
                {
                    Result = "OK",
                    Record = inputPortView
                });
            }
            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 InputPortView record)
 {
     var inputs = _deviceContext.InputPorts.Find(record.Id);
     if (inputs == null) return false;
     record.Device = inputs.Device;
     Mapper.Map(record, inputs);
     try
     {
         _deviceContext.SaveChanges();
         Mapper.Map(record, inputs);
         return true;
     }
     catch (Exception exception)
     {
         LogTo.Fatal("Error while updating record\r\n Message: ");
         LogTo.Fatal(exception.Message);
         return false; ;
     }
 }