public async Task <IHttpActionResult> RegisterCompanyVehicle([FromUri] string compID, Vehicle_APTC model) { try { if (!ModelState.IsValid) { var modelErrors = new List <string>(); foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { modelErrors.Add(modelError.ErrorMessage == "" ? modelError.Exception.Message : modelError.ErrorMessage); } } return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), modelErrors[0].ToString()), new JsonMediaTypeFormatter())); } var vehicleKey = "vehicle_" + model.KeyID; if (await _bucket.ExistsAsync(vehicleKey)) { //return Content(HttpStatusCode.Conflict, new Error($"Vehicle '{model.KeyID}' already exists")); return(Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "170-Key ID already exists."), new JsonMediaTypeFormatter())); } // call third part api to check Vehicle is valid or not VehPlate vehPlate = new VehPlate(); if (model.VehPlate != null) { vehPlate.PlateNumber = model.VehPlate.PlateNumber; vehPlate.PlateCategory = model.VehPlate.PlateCategory; vehPlate.PlateSource = model.VehPlate.PlateSource; vehPlate.PlateCode = model.VehPlate.PlateCode; } Ownership ownership = new Ownership(); if (model.Ownership != null) { ownership.OwnershipType = model.Ownership.OwnershipType; ownership.OwnerID = model.Ownership.OwnerID; ownership.OwnerName = model.Ownership.OwnerName; ownership.LeasorName = model.Ownership.LeasorName; } List <AuditInfo> lstauditInfo = new List <AuditInfo>(); AuditInfo auditInfo = new AuditInfo(); auditInfo.Version = "1"; auditInfo.Status = "true"; auditInfo.LastChangeDate = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()); auditInfo.LastChangeBy = model.KeyID; lstauditInfo.Add(auditInfo); CTResponse cTResponse = new CTResponse(); if (model.CTResponse != null) { cTResponse.CTStatus = false; cTResponse.CTResponseId = model.CTResponse.CTResponseId; cTResponse.CTRemarks = model.CTResponse.CTRemarks; } var vehicleDoc = new Document <Vehicle_APTC>() { Id = vehicleKey, Content = new Vehicle_APTC { //Id = vehicleKey, KeyID = model.KeyID, // This is vehicle chassNumber. DocType = model.DocType, EngineNum = model.EngineNum, NumSeats = model.NumSeats, TrafficNum = model.TrafficNum, FirstRegData = model.FirstRegData, YearManufacture = model.YearManufacture, Make = model.Make, Model = model.Model, Colour = model.Colour, VehType = model.VehType, FuelType = model.FuelType, TransType = model.TransType, IsActive = true, DisabledFriendly = model.DisabledFriendly, VehPlate = vehPlate, AuditInfo = lstauditInfo, CTResponse = cTResponse, Remarks = model.Remarks, Ownership = ownership, VehValid = false,// Third Part Verification Status = "PE" } }; var result = await _bucket.InsertAsync(vehicleDoc); if (!result.Success) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter())); } /////////////////////////////////// add vehicle to company schema if (model.Ownership.OwnershipType == "IND") { var individualDocument = _bucket.Query <object>(@"SELECT * From " + _bucket.Name + " as Company where meta().id= 'individual_" + model.Ownership.OwnerID + "'").ToList(); if (individualDocument.Count > 0) { Vehicles addnewVCehicleToCompany = new Vehicles(); addnewVCehicleToCompany.VehicleID = model.KeyID; //add document code string query = @"UPDATE " + _bucket.Name + " SET vehicles = ARRAY_APPEND(vehicles, " + Newtonsoft.Json.JsonConvert.SerializeObject(addnewVCehicleToCompany).ToString() + ") where meta().id='individual_" + model.Ownership.OwnerID + "'"; var resultIndividual = _bucket.Query <object>(query); //return Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), docOutID + " has been added sucessfully"), new JsonMediaTypeFormatter()); } } else if (compID.Trim() != string.Empty) { var companyDocument = _bucket.Query <object>(@"SELECT * From " + _bucket.Name + " as Company where meta().id= 'company_" + compID.Trim() + "'").ToList(); if (companyDocument.Count > 0) { Vehicles addnewVCehicleToCompany = new Vehicles(); addnewVCehicleToCompany.VehicleID = model.KeyID; //add document code string query = @"UPDATE " + _bucket.Name + " SET vehicles = ARRAY_APPEND(vehicles, " + Newtonsoft.Json.JsonConvert.SerializeObject(addnewVCehicleToCompany).ToString() + ") where meta().id='company_" + compID.Trim() + "'"; var resultIndividual = _bucket.Query <object>(query); //return Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), docOutID + " has been added sucessfully"), new JsonMediaTypeFormatter()); } } ///////////////////////////////// if (ConfigurationManager.AppSettings.Get("NotificationSettingFlag") == "1") { #region Post Notification RoleCodeHODP //////////////// Post Notification Code try { PostNotificationParameters objPostNotificationParameters = new PostNotificationParameters(); objPostNotificationParameters.UserCode = string.Empty; objPostNotificationParameters.RoleCode = AspectEnums.RoleCodeHODP; objPostNotificationParameters.DeptCode = AspectEnums.DeptCodeFROE; objPostNotificationParameters.NotificationType = (int)AspectEnums.NotificationType.VehicleRegistration; objPostNotificationParameters.KeyID = model.KeyID; objPostNotificationParameters.Value = model.TrafficNum; objPostNotificationParameters.Status = AspectEnums.StatusPS; //"PE";//model.Status.ToString(); resultPostNotification = sn.PostNotification(objPostNotificationParameters); //sn.PostNotification(); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } #endregion #region Post Notification RoleCodeBCKO //////////////// Post Notification Code try { PostNotificationParameters objPostNotificationParameters = new PostNotificationParameters(); objPostNotificationParameters.UserCode = string.Empty; objPostNotificationParameters.RoleCode = AspectEnums.RoleCodeBCKO; objPostNotificationParameters.DeptCode = AspectEnums.DeptCodeFROE; objPostNotificationParameters.NotificationType = (int)AspectEnums.NotificationType.VehicleRegistration; objPostNotificationParameters.KeyID = model.KeyID; objPostNotificationParameters.Value = model.TrafficNum; objPostNotificationParameters.Status = AspectEnums.StatusPS; //"PE";//model.Status.ToString(); resultPostNotification = sn.PostNotification(objPostNotificationParameters); //sn.PostNotification(); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } #endregion } return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Id), new JsonMediaTypeFormatter())); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } }
public async Task <IHttpActionResult> RegisterVehicle(Vehicle_APTC model) { try { if (!ModelState.IsValid) { var modelErrors = new List <string>(); foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { modelErrors.Add(modelError.ErrorMessage == "" ? modelError.Exception.Message : modelError.ErrorMessage); } } return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), modelErrors[0].ToString()), new JsonMediaTypeFormatter())); } var vehicleKey = "vehicle_" + model.KeyID; if (await _bucket.ExistsAsync(vehicleKey)) { //return Content(HttpStatusCode.Conflict, new Error($"Vehicle '{model.KeyID}' already exists")); return(Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "170-Key ID already exists."), new JsonMediaTypeFormatter())); } // call third part api to check Vehicle is valid or not VehPlate vehPlate = new VehPlate(); if (model.VehPlate != null) { vehPlate.PlateNumber = model.VehPlate.PlateNumber; vehPlate.PlateCategory = model.VehPlate.PlateCategory; vehPlate.PlateSource = model.VehPlate.PlateSource; vehPlate.PlateCode = model.VehPlate.PlateCode; } Ownership ownership = new Ownership(); if (model.Ownership != null) { ownership.OwnershipType = model.Ownership.OwnershipType; ownership.OwnerID = model.Ownership.OwnerID; ownership.OwnerName = model.Ownership.OwnerName; ownership.LeasorName = model.Ownership.LeasorName; } List <AuditInfo> lstauditInfo = new List <AuditInfo>(); AuditInfo auditInfo = new AuditInfo(); auditInfo.Version = "1"; auditInfo.Status = "true"; auditInfo.LastChangeDate = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()); auditInfo.LastChangeBy = model.KeyID; lstauditInfo.Add(auditInfo); CTResponse cTResponse = new CTResponse(); if (model.CTResponse != null) { cTResponse.CTStatus = false; cTResponse.CTResponseId = model.CTResponse.CTResponseId; cTResponse.CTRemarks = model.CTResponse.CTRemarks; } var vehicleDoc = new Document <Vehicle_APTC>() { Id = vehicleKey, Content = new Vehicle_APTC { //Id = vehicleKey, KeyID = model.KeyID, // This is vehicle chassNumber. DocType = model.DocType, EngineNum = model.EngineNum, NumSeats = model.NumSeats, TrafficNum = model.TrafficNum, FirstRegData = model.FirstRegData, YearManufacture = model.YearManufacture, Make = model.Make, Model = model.Model, Colour = model.Colour, VehType = model.VehType, FuelType = model.FuelType, TransType = model.TransType, IsActive = true, DisabledFriendly = model.DisabledFriendly, VehPlate = vehPlate, AuditInfo = lstauditInfo, CTResponse = cTResponse, Remarks = model.Remarks, Ownership = ownership, VehValid = false,// Third Part Verification Status = "PE" } }; var result = await _bucket.InsertAsync(vehicleDoc); if (!result.Success) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter())); } if (ConfigurationManager.AppSettings.Get("NotificationSettingFlag") == "1") { #region Post Notification RoleCodeHODP //////////////// Post Notification Code try { PostNotificationParameters objPostNotificationParameters = new PostNotificationParameters(); objPostNotificationParameters.UserCode = string.Empty; objPostNotificationParameters.RoleCode = AspectEnums.RoleCodeHODP; objPostNotificationParameters.DeptCode = AspectEnums.DeptCodeFROE; objPostNotificationParameters.NotificationType = (int)AspectEnums.NotificationType.VehicleRegistration; objPostNotificationParameters.KeyID = model.KeyID; objPostNotificationParameters.Value = model.TrafficNum; objPostNotificationParameters.Status = AspectEnums.StatusPS; //"PE";//model.Status.ToString(); resultPostNotification = sn.PostNotification(objPostNotificationParameters); //sn.PostNotification(); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } #endregion #region Post Notification RoleCodeBCKO //////////////// Post Notification Code try { PostNotificationParameters objPostNotificationParameters = new PostNotificationParameters(); objPostNotificationParameters.UserCode = string.Empty; objPostNotificationParameters.RoleCode = AspectEnums.RoleCodeBCKO; objPostNotificationParameters.DeptCode = AspectEnums.DeptCodeFROE; objPostNotificationParameters.NotificationType = (int)AspectEnums.NotificationType.VehicleRegistration; objPostNotificationParameters.KeyID = model.KeyID; objPostNotificationParameters.Value = model.TrafficNum; objPostNotificationParameters.Status = AspectEnums.StatusPS; //"PE";//model.Status.ToString(); resultPostNotification = sn.PostNotification(objPostNotificationParameters); //sn.PostNotification(); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } #endregion } return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Id + " Notification Status :" + resultPostNotification), new JsonMediaTypeFormatter())); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } }