public ActionResult AddDevice(DeviceModel deviceMl, string command) { StringBuilder objStringBuilderError = new StringBuilder(); try { if (Session["UserName"] != null && string.Equals(command, JetstreamResource.AddCommand) && deviceMl != null) { var duplicateLogicalDeviceId = CheckForDuplicateId(deviceMl); var duplicateSerial = CheckForDuplicateSerial(deviceMl); if (duplicateLogicalDeviceId == 1 || duplicateSerial == 1) { Warning(JetstreamResource.DuplicateAddDeviceMessage, true); return RedirectToAction("RedirectToAddDevice", new RouteValueDictionary(deviceMl)); } else { if (ModelState.IsValid) { // construct a Jetstream service client JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey); //Make logical device request object AddLogicalDeviceRequest request = new AddLogicalDeviceRequest { DeviceDefinitionId = deviceMl.DeviceGuid, DeviceSerialNumber = deviceMl.SerialNumber, LogicalDeviceId = deviceMl.LogicalDeviceId, Region = (Regions)Enum.Parse(typeof(Regions), deviceMl.Region) }; // Add device to jetstream cloud AddLogicalDeviceResponse response = client.AddLogicalDevice(request); using (JetstreamClient objMainServiceClient = new JetstreamClient()) { objMainServiceClient.SaveDevice(deviceMl); } Success(string.Format(JetstreamResource.DeviceSaveMessage, deviceMl.LogicalDeviceId, response.Id), true); return RedirectToAction("DeviceDetail", "Device"); } else { return RedirectToAction("RedirectToAddDevice", new RouteValueDictionary(deviceMl)); } } } else if (string.Equals(command, JetstreamResource.CancelCommand)) { return RedirectToAction("DeviceDetail", "Device"); } else { return RedirectToAction("UserLogin", "Login"); } } catch (FaultException<ServiceData> fex) { objStringBuilderError.AppendLine("In method : AddDevice(DeviceModel deviceMl, string command) :: DeviceController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } catch (Exception ex) { objStringBuilderError.AppendLine("In method : AddDevice(DeviceModel deviceMl, string command) :: DeviceController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString()); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } }