private async Task CreateDocument() { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Title", Title), }; if (FieldValidation.ValidateFields(values)) { CanSaveDocument = false; try { string UploadPath = ""; DocumentModel documentData = new DocumentModel() { Title = Title, ProjectID = ParentLayout.SelectedProject.ID, }; HttpResponseMessage result = null; if (isUpdate) { documentData.ID = ID; documentData.CreatedBy = SelectedDocument.CreatedBy; documentData.CreatedOn = SelectedDocument.CreatedOn; documentData.DocUrl = SelectedDocument.DocUrl; if (!string.IsNullOrEmpty(FilePath)) { UploadPath = $"{ConfigurationManager.AppSettings["FTPUrl"]}/Documents/{Guid.NewGuid()}.{FilePath.Substring(FilePath.IndexOf(".") + 1, FilePath.Length - FilePath.IndexOf(".") - 1)}"; FTPHelper.UploadFile(FilePath, UploadPath); documentData.DocUrl = UploadPath; } result = await apiHelper.PutDocument(ParentLayout.LoggedInUser.Token, documentData).ConfigureAwait(false); } else { if (string.IsNullOrEmpty(FilePath)) { MessageBox.Show("Please select a document to upload", "Select Document", MessageBoxButton.OK, MessageBoxImage.Warning); CanSaveDocument = true; return; } else { UploadPath = $"{ConfigurationManager.AppSettings["FTPUrl"]}/Documents/{Guid.NewGuid()}.{FilePath.Substring(FilePath.IndexOf(".") + 1, FilePath.Length - FilePath.IndexOf(".") - 1)}"; FTPHelper.UploadFile(FilePath, UploadPath); } documentData.DocUrl = UploadPath; documentData.CreatedBy = ParentLayout.LoggedInUser.Name; result = await apiHelper.PostDocument(ParentLayout.LoggedInUser.Token, documentData).ConfigureAwait(false); } if (result.IsSuccessStatusCode) { MessageBox.Show($"Document Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); await GetDocuments(); #region Log Data ActivityLogModel logData = new ActivityLogModel() { Type = "Document", Description = $"Document '{documentData.Title}' created by '{ParentLayout.LoggedInUser.Name}'", ProjectID = ParentLayout.SelectedProject.ID, CreatedBy = ParentLayout.LoggedInUser.Name, CreatedOn = DateTime.Now }; if (isUpdate) { logData.Description = $"Sheet '{documentData.Title}' updated by '{ParentLayout.LoggedInUser.Name}'"; } await logAPIHelper.PostActivityLog(ParentLayout.LoggedInUser.Token, logData); #endregion ClearFields(); IsUpdate = false; } else { MessageBox.Show("Error in saving Document", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanSaveDocument = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanSaveDocument = true; } } }
private async Task CreateTask() { try { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Title", Title), new KeyValuePair <string, string>("Task Type", TypeText), new KeyValuePair <string, string>("Task Status", StatusText), new KeyValuePair <string, string>("Task Stamp", StampText), new KeyValuePair <string, string>("Sheet", SelectedSheet?.Title), }; if (FieldValidation.ValidateFields(values)) { if (WatchingMembers.Count() <= 0) { MessageBox.Show("Please add atleast 1 Team Member to the Task", "Add Team Members", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (WatchingMembers.Where(w => w.IsWatcher).Count() <= 0) { MessageBox.Show("Please select watching members from the Selected Team Members", "Select Watching Members", MessageBoxButton.OK, MessageBoxImage.Warning); } else { CanSaveTask = false; List <TaskMembersModel> taskMembers = new List <TaskMembersModel>(); List <TaskWatchersModel> taskWatchers = new List <TaskWatchersModel>(); TeamMembers.Where(s => s.IsChecked).ToList().ForEach(s => taskMembers.Add( new TaskMembersModel { TaskID = ID, SiteManagerID = s.ID, })); WatchingMembers.Where(s => s.IsWatcher).ToList().ForEach(s => taskWatchers.Add( new TaskWatchersModel { TaskID = ID, SiteManagerID = s.ID, })); TaskModel taskData = new TaskModel() { ProjectID = ParentLayout.SelectedProject.ID, Title = Title, Description = Description, TaskStatusID = SelectedStatus?.ID, Status = SelectedStatus == null ? new StatusModel { Title = StatusText, CreatedBy = ParentLayout.LoggedInUser.Name } : null, TaskTypeID = SelectedType?.ID, Type = SelectedType == null ? new TypeModel { Title = TypeText, CreatedBy = ParentLayout.LoggedInUser.Name } : null, StartDate = StartDate, DueDate = DueDate, Members = taskMembers, Watchers = taskWatchers, StampID = SelectedStamp?.ID, Stamp = SelectedStamp == null ? new StampModel { Title = StampText, CreatedBy = ParentLayout.LoggedInUser.Name } : null, SheetID = SelectedSheet?.ID, }; HttpResponseMessage result = null; if (isUpdate) { taskData.ID = ID; taskData.CreatedBy = SelectedTask.CreatedBy; taskData.CreatedOn = SelectedTask.CreatedOn; taskData.ModifiedBy = ParentLayout.LoggedInUser.Name; taskData.ModifiedOn = DateTime.Now; result = await apiHelper.PutTask(ParentLayout.LoggedInUser.Token, taskData).ConfigureAwait(false); } else { taskData.CreatedBy = ParentLayout.LoggedInUser.Name; taskData.CreatedOn = DateTime.Now; result = await apiHelper.PostTask(ParentLayout.LoggedInUser.Token, taskData).ConfigureAwait(false); } if (result.IsSuccessStatusCode) { MessageBox.Show($"Task Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); await GetTasks(); #region Log Data ActivityLogModel logData = new ActivityLogModel() { Type = "Task", Description = $"Task '{taskData.Title}' created by '{ParentLayout.LoggedInUser.Name}'", ProjectID = ParentLayout.SelectedProject.ID, CreatedBy = ParentLayout.LoggedInUser.Name, CreatedOn = DateTime.Now }; if (isUpdate) { logData.Description = $"Task '{taskData.Title}' updated by '{ParentLayout.LoggedInUser.Name}'"; } await logAPIHelper.PostActivityLog(ParentLayout.LoggedInUser.Token, logData); #endregion IsUpdate = false; ClearFields(); await GetStamps(); await GetTypes(); await GetStatuses(); await GetTeamMembers(); } else { MessageBox.Show("Error in saving Task", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanSaveTask = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanSaveTask = true; } }
private async Task CreateQuotation() { try { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Vendor", Vendor), new KeyValuePair <string, string>("Narration", Narration), new KeyValuePair <string, string>("Cost", Cost.ToString()), new KeyValuePair <string, string>("Material", Material?.Name), }; if (FieldValidation.ValidateFields(values)) { CanSaveQuotation = false; string UploadPath = ""; QuotationModel quotationData = new QuotationModel() { Vendor = Vendor, MaterialID = Material.ID, Cost = Cost, Narration = Narration, CreatedBy = ParentLayout.LoggedInUser.Name, }; HttpResponseMessage result = null; if (isUpdate) { quotationData.ID = ID; quotationData.CreatedBy = SelectedQuotation.CreatedBy; quotationData.ModifiedOn = DateTime.Now; quotationData.ModifiedBy = ParentLayout.LoggedInUser.Name; if (!string.IsNullOrEmpty(FilePath)) { UploadPath = $"{ConfigurationManager.AppSettings["FTPUrl"]}/Documents/{Guid.NewGuid()}.{FilePath.Substring(FilePath.IndexOf(".") + 1, FilePath.Length - FilePath.IndexOf(".") - 1)}"; FTPHelper.UploadFile(FilePath, UploadPath); quotationData.DocUrl = UploadPath; } result = await apiHelper.PutQuotation(ParentLayout.LoggedInUser.Token, quotationData).ConfigureAwait(false); } else { if (!string.IsNullOrEmpty(FilePath)) { UploadPath = $"{ConfigurationManager.AppSettings["FTPUrl"]}/Documents/{Guid.NewGuid()}.{FilePath.Substring(FilePath.IndexOf(".") + 1, FilePath.Length - FilePath.IndexOf(".") - 1)}"; FTPHelper.UploadFile(FilePath, UploadPath); } quotationData.DocUrl = UploadPath; quotationData.CreatedBy = ParentLayout.LoggedInUser.Name; result = await apiHelper.PostQuotation(ParentLayout.LoggedInUser.Token, quotationData).ConfigureAwait(false); } if (result.IsSuccessStatusCode) { MessageBox.Show($"Quotation Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); await GetQuotations(); #region Log Data ActivityLogModel logData = new ActivityLogModel() { Type = "Quotation", Description = $"Quotation for '{quotationData.Vendor}' created by '{ParentLayout.LoggedInUser.Name}'", CreatedBy = ParentLayout.LoggedInUser.Name, CreatedOn = DateTime.Now }; if (isUpdate) { logData.Description = $"Quotation for '{quotationData.Vendor}' updated by '{ParentLayout.LoggedInUser.Name}'"; } await logAPIHelper.PostActivityLog(ParentLayout.LoggedInUser.Token, logData); #endregion IsUpdate = false; ClearFields(); } else { MessageBox.Show("Error in saving Quotation", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanSaveQuotation = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanSaveQuotation = true; } }
private async Task CreateCustomer() { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Name", CustomerName), new KeyValuePair <string, string>("Phone Numbers", PhoneNumbers), new KeyValuePair <string, string>("GSTN", GSTN), }; if (FieldValidation.ValidateFields(values)) { try { if (Flats == null && MessageBox.Show("Are you sure you want to proceed without adding flats?", "Add Flats", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } CanSaveCustomer = false; CustomerModel customerData = new CustomerModel() { Name = CustomerName, Email = Email, GSTN = GSTN, PhoneNumbers = PhoneNumbers, CurrentAddress = CurrentAddress, PAN = PAN, Aadhaar = Aadhaar, ReferredBy = ReferredBy, Flats = Flats }; HttpResponseMessage result = null; if (isUpdate) { customerData.ID = ID; customerData.Flats = customerData.Flats.Select(f => { f.CustomerId = customerData.ID; return(f); }).ToList(); customerData.CreatedBy = SelectedCustomer.CreatedBy; customerData.ModifiedOn = DateTime.Now; customerData.ModifiedBy = ParentLayout.LoggedInUser.Name; result = await apiHelper.PutCustomer(ParentLayout.LoggedInUser.Token, customerData).ConfigureAwait(false); } else { customerData.CreatedBy = ParentLayout.LoggedInUser.Name; result = await apiHelper.PostCustomer(ParentLayout.LoggedInUser.Token, customerData).ConfigureAwait(false); } if (result.IsSuccessStatusCode) { MessageBox.Show($"Customer Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); await GetCustomers(); #region Log Data ActivityLogModel logData = new ActivityLogModel() { Type = "Customer", Description = $"Customer '{customerData.Name}' created by '{ParentLayout.LoggedInUser.Name}'", CreatedBy = ParentLayout.LoggedInUser.Name, CreatedOn = DateTime.Now }; if (isUpdate) { logData.Description = $"Customer '{customerData.Name}' updated by '{ParentLayout.LoggedInUser.Name}'"; } await logAPIHelper.PostActivityLog(ParentLayout.LoggedInUser.Token, logData); #endregion ClearFields(); } else { MessageBox.Show("Error in saving Customer", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanSaveCustomer = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanSaveCustomer = true; } } }