Ejemplo n.º 1
0
        private async Task CreateSupplier()
        {
            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Name", SupplierName),
                new KeyValuePair <string, string>("Phone", Phone),
                new KeyValuePair <string, string>("Email", Email),
                new KeyValuePair <string, string>("GSTN", GSTN),
                new KeyValuePair <string, string>("WorkDescription", WorkDescription)
            };

            if (FieldValidation.ValidateFields(values))
            {
                CanSaveSupplier = false;
                try
                {
                    SupplierModel supplierData = new SupplierModel()
                    {
                        Name            = SupplierName,
                        Phone           = phone,
                        Email           = Email,
                        GSTN            = GSTN,
                        WorkDescription = WorkDescription,
                    };
                    HttpResponseMessage result = null;
                    if (isUpdate)
                    {
                        supplierData.ID         = ID;
                        supplierData.CreatedBy  = SelectedSupplier.CreatedBy;
                        supplierData.ModifiedOn = DateTime.Now;
                        supplierData.ModifiedBy = ParentLayout.LoggedInUser.Name;
                        result = await apiHelper.PutSupplier(ParentLayout.LoggedInUser.Token, supplierData).ConfigureAwait(false);
                    }
                    else
                    {
                        supplierData.CreatedBy = ParentLayout.LoggedInUser.Name;
                        result = await apiHelper.PostSupplier(ParentLayout.LoggedInUser.Token, supplierData).ConfigureAwait(false);
                    }
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Supplier Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        await GetSuppliers();

                        IsUpdate = false;
                        ClearFields();
                    }
                    else
                    {
                        MessageBox.Show("Error in saving Supplier", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveSupplier = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    CanSaveSupplier = true;
                }
            }
        }
Ejemplo n.º 2
0
        private async Task CreateSalesEnquiry()
        {
            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Name", Title),
                new KeyValuePair <string, string>("Phone", Phone),
                new KeyValuePair <string, string>("RelatedTo", RelatedTo),
                new KeyValuePair <string, string>("EnquiryDate", EnquiryDate.ToString()),
                new KeyValuePair <string, string>("FollowUpDate", FollowUpDate.ToString()),
            };

            if (FieldValidation.ValidateFields(values))
            {
                CanSaveEnquiry = false;
                try
                {
                    SalesEnquiryModel salesEnquiryData = new SalesEnquiryModel()
                    {
                        Name         = Title,
                        Phone        = Phone,
                        RelatedTo    = RelatedTo,
                        EnquiryDate  = EnquiryDate,
                        FollowUpDate = FollowUpDate,
                    };
                    HttpResponseMessage result = null;
                    if (isUpdate)
                    {
                        salesEnquiryData.ID         = ID;
                        salesEnquiryData.CreatedBy  = SelectedEnquiry.CreatedBy;
                        salesEnquiryData.ModifiedOn = DateTime.Now;
                        salesEnquiryData.ModifiedBy = ParentLayout.LoggedInUser.Name;
                        result = await apiHelper.PutSalesEnquiry(ParentLayout.LoggedInUser.Token, salesEnquiryData).ConfigureAwait(false);
                    }
                    else
                    {
                        salesEnquiryData.CreatedBy = ParentLayout.LoggedInUser.Name;
                        result = await apiHelper.PostSalesEnquiry(ParentLayout.LoggedInUser.Token, salesEnquiryData).ConfigureAwait(false);
                    }
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Sales Enquiry Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        await GetEnquiries();

                        ClearFields();
                    }
                    else
                    {
                        MessageBox.Show("Error in saving Sales Enquiry", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveEnquiry = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    CanSaveEnquiry = true;
                }
            }
        }
Ejemplo n.º 3
0
        private async Task CreateProject()
        {
            try
            {
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("Title", Title_),
                    new KeyValuePair <string, string>("Project Type", TypeText),
                    new KeyValuePair <string, string>("Project Status", StatusText),
                    new KeyValuePair <string, string>("Address", Address)
                };
                if (FieldValidation.ValidateFields(values))
                {
                    CanSaveProject = false;

                    ProjectModel projectData = new ProjectModel()
                    {
                        Title         = Title_,
                        ProjectTypeID = SelectedType?.ID,
                        Type          = SelectedType == null ? new TypeModel {
                            Title = TypeText, CreatedBy = ProjectSelection.LoggedInUser.Name
                        } : null,
                        ProjectStatusID = SelectedStatus?.ID,
                        Status          = SelectedStatus == null ? new StatusModel {
                            Title = StatusText, CreatedBy = ProjectSelection.LoggedInUser.Name
                        } : null,
                        StartDate = StartDate,
                        DueDate   = DueDate,
                        Address   = Address,
                        CreatedBy = ProjectSelection.LoggedInUser.Name,
                        CreatedOn = DateTime.Now
                    };

                    HttpResponseMessage result = await apiHelper.PostProject(ProjectSelection.LoggedInUser.Token, projectData).ConfigureAwait(false);

                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Project Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            new Action(async() => await ProjectSelection.GetProjects(null))();
                            ClosePopupCommand.Execute(null);
                        });
                    }
                    else
                    {
                        MessageBox.Show("Error in saving Project", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveProject = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CanSaveProject = true;
            }
        }
        private async Task CreateMaterial()
        {
            try
            {
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("Name", Title),
                    new KeyValuePair <string, string>("Unit", UnitText)
                };
                if (FieldValidation.ValidateFields(values))
                {
                    CanSaveMaterial = false;

                    MaterialModel materialData = new MaterialModel()
                    {
                        Name   = Title,
                        UnitID = SelectedUnit?.ID,
                        Unit   = SelectedUnit == null ? new UnitModel {
                            Title = UnitText, CreatedBy = ParentLayout.LoggedInUser.Name, CreatedOn = DateTime.Now
                        } : null,
                    };

                    HttpResponseMessage result = null;
                    if (isUpdate)
                    {
                        materialData.ID        = ID;
                        materialData.CreatedBy = selectedMaterial.CreatedBy;
                        result = await apiHelper.PutMaterial(ParentLayout.LoggedInUser.Token, materialData).ConfigureAwait(false);
                    }
                    else
                    {
                        materialData.CreatedBy = ParentLayout.LoggedInUser.Name;
                        result = await apiHelper.PostMaterial(ParentLayout.LoggedInUser.Token, materialData).ConfigureAwait(false);
                    }
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Material Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        await GetMaterials();
                        await GetUnits();

                        ClearFields();
                    }
                    else
                    {
                        MessageBox.Show("Error in saving Material", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveMaterial = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CanSaveMaterial = true;
            }
        }
Ejemplo n.º 5
0
        private async Task CreateUnit()
        {
            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Title", Title)
            };

            if (FieldValidation.ValidateFields(values))
            {
                CanSaveUnit = false;
                try
                {
                    UnitModel unitData = new UnitModel()
                    {
                        Title = Title,
                    };
                    HttpResponseMessage result = null;
                    if (isUpdate)
                    {
                        unitData.ID        = ID;
                        unitData.CreatedBy = SelectedUnit.CreatedBy;
                        result             = await apiHelper.PutUnit(ParentLayout.LoggedInUser.Token, unitData).ConfigureAwait(false);
                    }
                    else
                    {
                        unitData.CreatedBy = ParentLayout.LoggedInUser.Name;
                        result             = await apiHelper.PostUnit(ParentLayout.LoggedInUser.Token, unitData).ConfigureAwait(false);
                    }
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Unit Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        await GetUnits();

                        ClearFields();
                        IsUpdate = false;
                    }
                    else
                    {
                        MessageBox.Show("Error in saving Unit", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveUnit = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    CanSaveUnit = true;
                }
            }
        }
Ejemplo n.º 6
0
        private async Task DoLogin()
        {
            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("UserName", UserName),
                new KeyValuePair <string, string>("Password", Password)
            };

            if (FieldValidation.ValidateFields(values))
            {
                CanLogin = false;
                try
                {
                    LoginAPIHelper loginAPIHelper = new LoginAPIHelper();
                    var            result         = await loginAPIHelper.Authenticate(UserName, Password).ConfigureAwait(false);

                    if (result.GetType() == typeof(LoginErrorResponse))
                    {
                        LoginErrorResponse response = result as LoginErrorResponse;
                        MessageBox.Show(response.Error_Description, response.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else if (result.GetType() == typeof(AuthenticatedUser))
                    {
                        AuthenticatedUser authenticatedUser = result as AuthenticatedUser;
                        LoggedInUser      loggedInUser      = await loginAPIHelper.GetLoggedInUser(authenticatedUser.Access_Token).ConfigureAwait(false);

                        loggedInUser.Token = authenticatedUser.Access_Token;
                        Application.Current.Properties["LoggedInUser"] = loggedInUser;
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            ProjectSelection projectSelection = new ProjectSelection();
                            projectSelection.Show();
                            this.Close();
                        });
                    }
                    else
                    {
                        MessageBox.Show("OOPS! Unexpected error occured", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanLogin = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    CanLogin = true;
                }
            }
        }
        private async Task CreateProject()
        {
            try
            {
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("Title", Title),
                    new KeyValuePair <string, string>("Project Type", TypeText),
                    new KeyValuePair <string, string>("Project Status", StatusText),
                    new KeyValuePair <string, string>("Firm", FirmText),
                    new KeyValuePair <string, string>("Address", Address)
                };
                if (FieldValidation.ValidateFields(values))
                {
                    if (Contractors.Where(c => c.IsChecked).Count() <= 0)
                    {
                        MessageBox.Show("Please add atleast 1 Contractor to the Project", "Add Contractor", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else if (Suppliers.Where(c => c.IsChecked).Count() <= 0)
                    {
                        MessageBox.Show("Please add atleast 1 Supplier to the Project", "Add Supplier", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else
                    {
                        CanSaveProject = false;

                        List <ProjectContractorsModel> projectContractors = new List <ProjectContractorsModel>();
                        List <ProjectSuppliersModel>   projectSuppliers   = new List <ProjectSuppliersModel>();

                        Contractors.Where(s => s.IsChecked).ToList().ForEach(s => projectContractors.Add(
                                                                                 new ProjectContractorsModel
                        {
                            ProjectID    = ID,
                            ContractorID = s.ID,
                        }));

                        Suppliers.Where(s => s.IsChecked).ToList().ForEach(s => projectSuppliers.Add(
                                                                               new ProjectSuppliersModel
                        {
                            ProjectID  = ID,
                            SupplierID = s.ID,
                        }));

                        ProjectModel projectData = new ProjectModel()
                        {
                            Title         = Title,
                            Description   = Description,
                            ProjectTypeID = SelectedType?.ID,
                            Type          = SelectedType == null ? new TypeModel {
                                Title = TypeText, CreatedBy = ParentLayout.LoggedInUser.Name
                            } : null,
                            ProjectStatusID = SelectedStatus?.ID,
                            Status          = SelectedStatus == null ? new StatusModel {
                                Title = StatusText, CreatedBy = ParentLayout.LoggedInUser.Name
                            } : null,
                            FirmID = SelectedFirm?.ID,
                            Firm   = SelectedFirm == null ? new FirmModel {
                                Name = FirmText, CreatedBy = ParentLayout.LoggedInUser.Name
                            } : null,
                            StartDate   = StartDate,
                            DueDate     = DueDate,
                            Address     = Address,
                            TeamID      = SelectedTeam?.ID,
                            Contractors = projectContractors,
                            Suppliers   = projectSuppliers
                        };

                        HttpResponseMessage result = null;
                        if (isUpdate)
                        {
                            projectData.ID         = ID;
                            projectData.CreatedBy  = SelectedProject.CreatedBy;
                            projectData.CreatedOn  = SelectedProject.CreatedOn;
                            projectData.ModifiedBy = ParentLayout.LoggedInUser.Name;
                            projectData.ModifiedOn = DateTime.Now;
                            result = await apiHelper.PutProject(ParentLayout.LoggedInUser.Token, projectData).ConfigureAwait(false);
                        }
                        else
                        {
                            projectData.CreatedBy = ParentLayout.LoggedInUser.Name;
                            projectData.CreatedOn = DateTime.Now;
                            result = await apiHelper.PostProject(ParentLayout.LoggedInUser.Token, projectData).ConfigureAwait(false);
                        }
                        if (result.IsSuccessStatusCode)
                        {
                            MessageBox.Show($"Project Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            await GetProjects();

                            await ParentLayout.GetProjects();

                            IsUpdate = false;
                            ClearFields();
                            await GetContractors();
                            await GetSuppliers();
                            await GetTypes();
                            await GetStatuses();
                            await GetFirms();
                        }
                        else
                        {
                            MessageBox.Show("Error in saving Project", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        CanSaveProject = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CanSaveProject = true;
            }
        }
        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 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 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 CreateTeam()
        {
            try
            {
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("Title", Title)
                };
                if (FieldValidation.ValidateFields(values))
                {
                    if (SiteManagers.Where(s => s.IsChecked).Count() > 0)
                    {
                        CanSaveTeam = false;

                        List <TeamSiteManagersModel> teamSiteManagers = new List <TeamSiteManagersModel>();

                        SiteManagers.Where(s => s.IsChecked).ToList().ForEach(s => teamSiteManagers.Add(
                                                                                  new TeamSiteManagersModel
                        {
                            TeamID        = ID,
                            SiteManagerID = s.ID,
                            CreatedBy     = parentLayout.LoggedInUser.Name
                        }));
                        TeamModel teamData = new TeamModel()
                        {
                            Name             = Title,
                            TeamSiteManagers = teamSiteManagers
                        };

                        HttpResponseMessage result = null;
                        if (isUpdate)
                        {
                            teamData.ID        = ID;
                            teamData.CreatedBy = SelectedTeam.CreatedBy;
                            result             = await apiHelper.PutTeam(ParentLayout.LoggedInUser.Token, teamData).ConfigureAwait(false);
                        }
                        else
                        {
                            teamData.CreatedBy = ParentLayout.LoggedInUser.Name;
                            result             = await apiHelper.PostTeam(ParentLayout.LoggedInUser.Token, teamData).ConfigureAwait(false);
                        }

                        if (result.IsSuccessStatusCode)
                        {
                            MessageBox.Show($"Team Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            await GetTeams();

                            ClearFields();
                            await GetSiteManagers();

                            IsUpdate = false;
                        }
                        else
                        {
                            MessageBox.Show("Team Saving Failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        CanSaveTeam = true;
                    }
                }
                else
                {
                    MessageBox.Show("Please add atleast 1 SiteManager to the Team", "Add Managers", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CanSaveTeam = true;
            }
        }
Ejemplo n.º 12
0
        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;
                }
            }
        }