/// <summary> /// Method Name : ExecutePostAlertList /// Author : Pratik Soni /// Creation Date : 05 Feb 2018 /// Purpose : Executes the CRM post service for each Alert from the list /// Revision : /// </summary> /// <param name="requestObject"/> /// <param name="customerID"/> /// <returns></returns> private string ExecutePostAlertList(DTO.Alert requestObject, string customerID) { ServiceResponse <Alert> crmResponse; Dictionary <string, string> customerResponse; try { if (!crmCustomerDetails.CheckCustomerRegistered(customerID)) { logger.Error(resourceManager.GetString("msgInvalidCustomer")); return(GenerateServiceResponse <ServiceResponse <Alert> >(BADREQUEST, resourceManager.GetString("msgInvalidCustomer"))); } customerResponse = crmCustomerDetails.GetCustomerGUID(customerID); requestObject.CustomerID = General.GetSpecificAttributeFromCRMResponse(customerResponse, "contactid"); crmResponse = crmAlertDetails.PostAlertDetails(customerID, General.ConvertToJson <Alert>(requestObject)); if (!Validations.IsValid(crmResponse.Information)) { logger.Error(resourceManager.GetString("msgErrorInInsertingNewAlert") + requestObject.AlertTitle); return(General.ConvertToJson <ServiceResponse <Alert> >(crmResponse)); } logger.Info(resourceManager.GetString("msgSavedSuccessfully")); return(General.ConvertToJson <ServiceResponse <Alert> >(new ServiceResponse <Alert> { })); } catch (Exception ex) { logger.Error(resourceManager.GetString("msgFailToSave"), ex); return(GenerateServiceResponse <DTO.Alert>(MESSAGE, resourceManager.GetString("msgFailToSave"))); } }
/// <summary> /// Method Name : RetriveLastAlertId /// Author : Pratik Soni /// Creation Date : 02 Jan 2018 /// Purpose : To get the ID of last inserted record. /// Revision : /// </summary> /// <returns></returns> private int RetriveLastAlertId() { DTO.Alert alert = new DTO.Alert(); alert = GetLastAlertID(); if (alert == null) { logger.Error("Unable to get Last alert ID"); return(-1); } return(0);// modified to return 0 if AlertID not found or NULL found }
/// <summary> /// Method Name : IsRequestDataValid /// Author : Pratik Soni /// Creation Date : 02 Jan 2018 /// Purpose : To validate request data /// Revision : /// </summary> /// <param name="requestObject"></param> /// <param name="checkForPostRequest">if it is false, it will execute for PUT request </param> /// <param name="customerID"> We don't need customerID for PUT request </param> /// <returns></returns> private bool IsRequestDataValid(DTO.Alert requestObject, bool checkForPostRequest = false, string customerID = "") { string customerIDValue = string.Empty; if (checkForPostRequest) { customerIDValue = customerID; } else { customerIDValue = requestObject.CustomerID; } if (string.IsNullOrEmpty(customerIDValue) || string.IsNullOrEmpty(requestObject.AlertTitle) || string.IsNullOrEmpty(Convert.ToString(requestObject.StartDate)) || string.IsNullOrEmpty(Convert.ToString(requestObject.EndDate))) { logger.Info(resourceManager.GetString("msgValidateRequestContentFail")); return(false); } logger.Info(resourceManager.GetString("msgValidateRequestContent")); return(true); }
/// <summary> /// Method Name : ValidateRequestContent /// Author : Pratik Soni /// Creation Date : 05 Feb 2018 /// Purpose : To validate request content DTO for POST alert method /// Revision : /// </summary> /// <returns>BadRequest if validation fails, else returns NULL ServiceResponse </returns> private ServiceResponse <Alert> ValidateRequestContent(DTO.Alert requestObject, string customerID) { try { if (!IsRequestDataValid(requestObject, true, customerID)) { logger.Info(resourceManager.GetString("msgBadRequest")); return(new ServiceResponse <Alert> { BadRequest = resourceManager.GetString("msgBadRequest") }); } return(new ServiceResponse <Alert> { }); } catch (Exception ex) { logger.Error(resourceManager.GetString("msgServiceUnavailable"), ex); return(new ServiceResponse <Alert> { Message = resourceManager.GetString("msgServiceUnavailable") }); } }
/// <summary> /// Method Name : ConvertDTOToDictionary /// Author : Pratik Soni /// Creation Date : 02 Jan 2018 /// Purpose : Update the given list of Alerts in "Alerts" table in SQL. /// Revision : /// </summary> /// <param name="alertID"/> /// <param name="alertTable"/> /// <param name="customerID"/> /// <param name="prepareForInsert"/> -- if there parameter is set to true only then alertID and customerID params will get used. /// <returns></returns> private Dictionary <string, dynamic> ConvertDTOToDictionary(DTO.Alert alertTable, int alertID = -1, string customerID = "", bool prepareForInsert = false) { Dictionary <string, dynamic> alertDetails = new Dictionary <string, dynamic>(); if (prepareForInsert) { alertDetails.Add("AlertID", alertID); alertDetails.Add("CustomerID", customerID); } else { alertDetails.Add("AlertID", alertTable.AlertID.ToString()); alertDetails.Add("CustomerID", alertTable.CustomerID.ToString()); } alertDetails.Add("AlertTitle", alertTable.AlertTitle.ToString()); alertDetails.Add("AlertDescription", (!string.IsNullOrEmpty(alertTable.AlertDescription) ? alertTable.AlertDescription : string.Empty)); alertDetails.Add("StartDate", General.GetSQLDateFormat(alertTable.StartDate.ToString())); alertDetails.Add("EndDate", General.GetSQLDateFormat(alertTable.EndDate.ToString())); alertDetails.Add("NotificationType", alertTable.NotificationType.ToString()); alertDetails.Add("IsActive", alertTable.IsActive.ToString()); return(alertDetails); }