public static ComplaintModel MapComplaintModel(this ComplaintsDTO ComplaintDTO) { return(new ComplaintModel() { ExternalId = ComplaintDTO.Id, ShopName = ComplaintDTO.ShopName, ShopAddress = ComplaintDTO.ShopAddress, DateOfInspection = ComplaintDTO.DateOfInspection, Violations = ComplaintDTO.Violations, GpsLocations = ComplaintDTO.GpsLocations, Cityid = ComplaintDTO.Cityid, SpeciesId = ComplaintDTO.SpeciesId, CreatedBy = ComplaintDTO.CreatedBy, CreatedDate = ComplaintDTO.CreatedDate ?? DateTime.Now, ModifiedDate = ComplaintDTO.ModifiedDate ?? DateTime.Now, ModifiedBy = ComplaintDTO.CreatedBy, IsEmptyModel = false, UserId = ComplaintDTO.UserId, ComplainStatus = ComplaintDTO.ComplainStatus, GroupName = ComplaintDTO.GroupName, IsActive = ComplaintDTO.IsActive, IsDelete = ComplaintDTO.IsDelete, ComplaintLowsId = ComplaintDTO.ComplaintLowsId, ComplaintFiles = ComplaintDTO.ComplaintFiles, Operation = (int)Operations.Sync, IsRejecet = ComplaintDTO.IsRejecet, CommentForRejection = ComplaintDTO.CommentForRejection, RegistrationDate = ComplaintDTO.RegistrationDate, IsRegister = ComplaintDTO.IsRegister, IsEmailSend = ComplaintDTO.IsEmailSend, }); }
public async Task <bool> UpdateComplaintOnServer(ComplaintsDTO complaintsDTO) { try { List <KeyValuePair <string, string> > ListOfParameters = new List <KeyValuePair <string, string> >(); ListOfParameters.Add(new KeyValuePair <string, string>("ShopName", complaintsDTO.ShopName)); ListOfParameters.Add(new KeyValuePair <string, string>("Id", Convert.ToString(complaintsDTO.Id))); ListOfParameters.Add(new KeyValuePair <string, string>("ShopAddress", complaintsDTO.ShopAddress)); ListOfParameters.Add(new KeyValuePair <string, string>("DateOfInspection", complaintsDTO.DateOfInspection?.ToString("dd-MMM-yyyy"))); ListOfParameters.Add(new KeyValuePair <string, string>("Comments", complaintsDTO.Comments ?? " ")); ListOfParameters.Add(new KeyValuePair <string, string>("Violations", complaintsDTO.Violations ?? " ")); ListOfParameters.Add(new KeyValuePair <string, string>("GpsLocations", complaintsDTO.GpsLocations ?? " ")); ListOfParameters.Add(new KeyValuePair <string, string>("UserId", _settings.UserId ?? " ")); ListOfParameters.Add(new KeyValuePair <string, string>("Cityid", Convert.ToString(_settings.UserCityId) ?? "0")); ListOfParameters.Add(new KeyValuePair <string, string>("SpeciesId", Convert.ToString(complaintsDTO.SpeciesId) ?? "0")); ListOfParameters.Add(new KeyValuePair <string, string>("ComplainStatus", Convert.ToString(complaintsDTO.ComplainStatus))); ListOfParameters.Add(new KeyValuePair <string, string>("GroupName", complaintsDTO.GroupName ?? " ")); ListOfParameters.Add(new KeyValuePair <string, string>("IsDelete", "false")); ListOfParameters.Add(new KeyValuePair <string, string>("IsActive", "true")); ListOfParameters.Add(new KeyValuePair <string, string>("LowIds", complaintsDTO.ComplaintLowsId)); ListOfParameters.Add(new KeyValuePair <string, string>("IsRejecet", Convert.ToString(complaintsDTO.IsRejecet ?? false))); ListOfParameters.Add(new KeyValuePair <string, string>("IsEmailSend", Convert.ToString(complaintsDTO.IsEmailSend ?? false))); ListOfParameters.Add(new KeyValuePair <string, string>("CommentForRejection", Convert.ToString(complaintsDTO.CommentForRejection ?? " "))); ListOfParameters.Add(new KeyValuePair <string, string>("RegistrationDate", complaintsDTO.RegistrationDate?.ToString("dd-MMMM-yyyy hh:mm:ss") ?? DateTime.Now.ToString("dd-MMMM-yyyy hh:mm:ss"))); ListOfParameters.Add(new KeyValuePair <string, string>("IsEmailSend", Convert.ToString(complaintsDTO.IsEmailSend ?? false))); List <byte[]> fileBlob = new List <byte[]>(); if (!string.IsNullOrEmpty(complaintsDTO.ComplaintFiles)) { List <string> SplitFilePaths = new List <string>(); SplitFilePaths = complaintsDTO.ComplaintFiles.Split(',')?.ToList(); if (SplitFilePaths.AnyExtended()) { foreach (var item in SplitFilePaths) { using (var webClient = new System.Net.WebClient()) { byte[] imageBytes = webClient.DownloadData(item); fileBlob.Add(imageBytes); } } } } var responce = await restapiHelper.SaveComplaint(EndPoint.Complaint.SaveComplaints, ListOfParameters, fileBlob); return(responce); } catch (Exception ex) { return(false); } }
private async Task CompalinStatusMethod(ComplaintsDTO complaints) { try { IsBusy = true; _complaintService.DeleteComplaint(); if (_settings.IsOnline) { IsBusy = true; ComplaintModelObj = await _complaintService.GetNonComplaintModel() ?? new ComplaintModel(); if (ComplaintModelObj != null) { ComplaintModelObj.ShopAddress = complaints.ShopAddress ?? ""; ComplaintModelObj.ShopName = complaints.ShopName ?? ""; ComplaintModelObj.Files = complaints.ComplaintFiles ?? ""; if (!string.IsNullOrEmpty(ComplaintModelObj.Files)) { List <string> SplitFilePaths = new List <string>(); List <string> AddFilePaths = new List <string>(); SplitFilePaths = ComplaintModelObj.Files.Split(',')?.ToList(); if (SplitFilePaths.AnyExtended()) { foreach (var item in SplitFilePaths) { var localFilePath = await FileExtensions.DownloadImageFromUrlSaveLocal(item); AddFilePaths.Add(localFilePath); } } ComplaintModelObj.Files = string.Join(",", AddFilePaths.ToArray()); ComplaintModelObj.ComplaintFiles = ComplaintModelObj.Files; } else { ComplaintModelObj.Files = ""; } ComplaintModelObj.ExternalId = complaints.Id; ComplaintModelObj.Operation = (int)Operations.Non; ComplaintModelObj.LowsId = complaints.ComplaintLowsId; ComplaintModelObj.ComplaintLowsId = complaints.ComplaintLowsId; ComplaintModelObj.ApplicationType = 1; ComplaintModelObj.IsEmptyModel = false; ComplaintModelObj.SpeciesName = complaints.SpeciesName; ComplaintModelObj.SpeciesId = complaints.SpeciesId; ComplaintModelObj.Violations = complaints.Violations; ComplaintModelObj.Cityid = _settings.UserCityId; ComplaintModelObj.ComplainStatus = complaints.ComplainStatus; ComplaintModelObj.IsActive = true; ComplaintModelObj.GpsLocations = complaints.GpsLocations; ComplaintModelObj.IsDelete = false; ComplaintModelObj.Comments = complaints.Comments; ComplaintModelObj.DateOfInspection = complaints.DateOfInspection; ComplaintModelObj.IsRejecet = complaints.IsRejecet ?? false; ComplaintModelObj.CommentForRejection = complaints.CommentForRejection; ComplaintModelObj.RegistrationDate = complaints.RegistrationDate ?? DateTime.UtcNow; ComplaintModelObj.IsRegister = complaints.IsRegister; ComplaintModelObj.IsEmailSend = complaints.IsEmailSend; ComplaintModelObj.CreatedBy = complaints.CreatedBy; ComplaintModelObj.ModifiedBy = complaints.ModifiedBy; ComplaintModelObj.CreatedDate = complaints.CreatedDate ?? DateTime.UtcNow; ComplaintModelObj.ModifiedDate = complaints.ModifiedDate ?? DateTime.UtcNow; ComplaintModelObj.CreatedUserName = complaints.CreatedUserName; ComplaintModelObj.UserMobileNumber = complaints.UserMobileNumber; ComplaintModelObj.ModifiedDate = complaints.ModifiedDate ?? DateTime.UtcNow; ComplaintModelObj.CityName = complaints.CityName; ComplaintModelObj.IsUpdate = false; await _complaintService.SaveComplaint(ComplaintModelObj); IsBusy = false; NavigationParameters navigationparameters = new NavigationParameters(); navigationparameters.Add("complaintdto", complaints); await NavigationService.NavigateAsync(new System.Uri($"/{AppPages.SSCMaster.SSCMasterPage}/{AppPages.NavigationPage}/{AppPages.DashBoard.HomePage}/{AppPages.DashBoard.ComplaintStatusPage}/{AppPages.ComplaintRegister.ComplaintOverviewPage}", System.UriKind.RelativeOrAbsolute), navigationparameters); } IsBusy = false; } else { _userDialogs.Toast("There is no INTERNET connection", new TimeSpan(20)); } IsBusy = false; } catch (Exception ex) { IsBusy = false; await PageDialogService.DisplayAlertAsync(null, AppAlertMessage.TechnicalError, "OK"); } }
public async Task <Responce <ComplaintsDTO> > SaveComplaint(HttpRequest complaintRequest, string UserName) { Responce <ComplaintsDTO> Responce = new Responce <ComplaintsDTO>(); Responce.Success = true; try { using (SSCEntities = new SSCEntities()) { Complaints complaints = new Complaints(); int Id = Convert.ToInt32(complaintRequest.Form["Id"]); var Cityid = Convert.ToInt32(complaintRequest.Form["Cityid"]); var SpeciesId = Convert.ToInt32(complaintRequest.Form["SpeciesId"]); complaints.City = Cityid; complaints.Id = Id; if (complaints.Id != 0) { complaints = SSCEntities.Complaints.Find(Id); var ComplaintLows = complaints.ComplaintsLows; var ComplaintImages = complaints.ComplaintImages; SSCEntities.ComplaintsLows.RemoveRange(ComplaintLows); SSCEntities.ComplaintImages.RemoveRange(ComplaintImages); await SSCEntities.SaveChangesAsync(); } complaints.SpeciesId = SpeciesId; complaints.ShopName = Convert.ToString(complaintRequest.Form["ShopName"]); complaints.ShopAddress = Convert.ToString(complaintRequest.Form["ShopAddress"]); complaints.DateOfInspection = Convert.ToDateTime(complaintRequest.Form["DateOfInspection"]); complaints.Comments = Convert.ToString(complaintRequest.Form["Comments"]); complaints.Violations = Convert.ToString(complaintRequest.Form["Violations"]); complaints.GpsLocations = Convert.ToString(complaintRequest.Form["GpsLocations"]); complaints.UserId = Convert.ToString(complaintRequest.Form["UserId"]); complaints.ComplainStatus = Convert.ToInt32(complaintRequest.Form["ComplainStatus"]); complaints.GroupName = Convert.ToString(complaintRequest.Form["GroupName"]); complaints.IsDelete = Convert.ToBoolean(complaintRequest.Form["IsDelete"]); complaints.IsActive = Convert.ToBoolean(complaintRequest.Form["IsActive"]); complaints.ModifiedBy = UserName ?? Convert.ToString(complaintRequest.Form["UserId"]); complaints.ModifiedDate = DateTime.UtcNow; complaints.IsRejecet = Convert.ToBoolean(complaintRequest.Form["IsRejecet"]); complaints.CommentForRejection = Convert.ToString(complaintRequest.Form["CommentForRejection"]); complaints.RegistrationDate = Convert.ToDateTime(complaintRequest.Form["RegistrationDate"]); complaints.IsRegister = Convert.ToBoolean(complaintRequest.Form["IsRegister"]); complaints.IsEmailSend = Convert.ToBoolean(complaintRequest.Form["IsEmailSend"]); if (complaints.Id != 0) { SSCEntities.Entry(complaints).State = EntityState.Modified; } else { complaints.CreatedBy = UserName ?? Convert.ToString(complaintRequest.Form["UserId"]); complaints.CreatedDate = DateTime.UtcNow; SSCEntities.Complaints.Add(complaints); } await SSCEntities.SaveChangesAsync(); var LowsIds = Convert.ToString(complaintRequest.Form["LowIds"]).Split(','); if (LowsIds.Count() > 0) { foreach (var item in LowsIds) { ComplaintsLows complaintsLows = new ComplaintsLows(); complaintsLows.LowId = Convert.ToInt32(item); complaintsLows.ComplaintId = complaints.Id; SSCEntities.ComplaintsLows.Add(complaintsLows); await SSCEntities.SaveChangesAsync(); } } if (complaintRequest.Files != null) { if (complaintRequest.Files.Count > 0) { for (int i = 0; i < complaintRequest.Files.Count; i++) { if (complaintRequest.Files[i].ContentLength > 0) { ComplaintImages complaintsImages = new ComplaintImages(); string extension = Path.GetExtension(complaintRequest.Files[i].FileName); bool isImage = Functions.IsImage(complaintRequest.Files[i].FileName); string ContentType = complaintRequest.Files[i].ContentType; string[] bloburi = AzureStore.UploadFile(complaintRequest.Files[i].InputStream, complaintRequest.Files[i].FileName, ContentType, isImage, extension); complaintsImages.ComplaintId = complaints.Id; complaintsImages.Imagetype = extension; complaintsImages.ImageUrl = bloburi[0]; complaintsImages.CreatedDate = DateTime.UtcNow; complaintsImages.ModifiedDate = DateTime.UtcNow; complaintsImages.CreatedBy = UserName; complaintsImages.ModifiedBy = UserName; SSCEntities.ComplaintImages.Add(complaintsImages); await SSCEntities.SaveChangesAsync(); } } //foreach (string item in complaintRequest.Files) //{ // var postedFile = complaintRequest.Files[item]; // if (!string.IsNullOrEmpty(postedFile.FileName)) // { // ComplaintImages complaintsImages = new ComplaintImages(); // string extension = Path.GetExtension(postedFile.FileName); // } // i = i + 1; //} } } ComplaintsDTO complaintsdto = new ComplaintsDTO(); SSCEntities db = new SSCEntities(); var saveComplaintobj = db.Complaints.Find(complaints.Id); complaintsdto = saveComplaintobj.MapComplaintsToDTO(); Responce.ResponeContent = complaintsdto; } } catch (Exception ex) { Responce.Success = false; Responce.Message = $"ERROR SaveComplaint :{ex.ToString()}"; } return(Responce); }