protected async Task<bool> SaveContacts(MasterEntity entity)
        {
            using (var c = NestedContainer)
            {
                if(!ContactsList.Any(n => n.IsDirty)) return true;

                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = new ResponseBool { Success = false };
                var itemsToSave = new List<ContactItem>();

                foreach (var item in ContactsList.Where(n => n.IsDirty))
                {
                    var contactItem = new ContactItem
                    {
                        MasterId = item.Contact.Id,
                        DateOfBirth = item.Contact.DateOfBirth,
                        MaritalStatusMasterId = (int)item.Contact.MStatus,
                        BusinessPhone = item.Contact.BusinessPhone,
                        ChildrenNames = item.Contact.ChildrenNames,
                        City = item.Contact.City,
                        Company = item.Contact.Company,
                        ContactClassification = (int)item.Contact.ContactClassification,
                        ContactOwnerType = item.Contact.ContactOwnerType,
                        ContactOwnerMasterId = entity.Id,
                        DateCreated = item.Contact._DateCreated,
                        Email = item.Contact.Email,
                        Fax = item.Contact.Fax,
                        Firstname = item.Contact.Firstname,
                        HomePhone = item.Contact.HomePhone,
                        HomeTown = item.Contact.HomeTown,
                        JobTitle = item.Contact.JobTitle,
                        Lastname = item.Contact.Lastname,
                        MobilePhone = item.Contact.MobilePhone,
                        PhysicalAddress = item.Contact.PhysicalAddress,
                        PostalAddress = item.Contact.PostalAddress,
                        SpouseName = item.Contact.SpouseName,
                        WorkExtPhone = item.Contact.WorkExtPhone,
                        DateLastUpdated = DateTime.Now,
                        StatusId = (int)EntityStatus.Active,
                        IsNew = item.IsNew
                    };
                    if (item.Contact.ContactType != null) contactItem.ContactTypeMasterId = item.Contact.ContactType.Id;
                    itemsToSave.Add(contactItem);
                }
                if (itemsToSave.Count > 0)
                {
                    response = await _proxy.ContactsAddAsync(itemsToSave.ToList());
                    MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage contacts", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                else response.Success = true;

                return response.Success;
            }
        }
        private async void Save()
        {
            DateTime now = DateTime.Now;
            CommoditySupplier.CommoditySupplierType = CommoditySupplierType.Individual;
            CommoditySupplier.JoinDate = now;
            CommoditySupplier.Contact.Clear();
            CommoditySupplier.Name = CommodityOwner.FullName;
            CommoditySupplier.BankId =SelectedBank!=null? SelectedBank.Id:Guid.Empty;
            CommoditySupplier.BankBranchId = SelectedBankBranch != null ? SelectedBankBranch.Id : Guid.Empty;
            CommoditySupplier.AccountNo = AccountNumber;
            CommoditySupplier.AccountName = AccountName;
            

            if (!IsValid(CommoditySupplier))
                return;

            CommodityOwner.CommodityOwnerType = SelectedCommodityOwnerType;
            CommodityOwner.MaritalStatus = SelectedMaritalStatus;
            CommodityOwner.DateOfBirth = DateOfBirth;
            if (DateOfBirth.Year < 18)
            {
                MessageBox.Show("Farmer must be over 18 years old.", "Agrimanagr: Farmer Management",
                                MessageBoxButton.OK);
                return;
            }
           
            CommodityOwner._SetStatus(EntityStatus.Active);

            if (!IsValid() || !IsValid(CommodityOwner)) return;

            CommodityProducer.CommodityProducerCentres.Clear();
            CommodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
            if (!IsValid() || !IsValid(CommodityProducer)) return;

            using (var c = NestedContainer)
            {
                string responseMsg = "";
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = await _proxy.CommoditySupplierAddAsync(CommoditySupplier);
                responseMsg += response.ErrorInfo + "\n";

                string log = string.Format("Created commodity supplier: {0}; Code: {1}; And Type {2}",
                                           CommoditySupplier.Name,
                                           CommoditySupplier.CostCentreCode, CommoditySupplier.CommoditySupplierType);
                Using<IAuditLogWFManager>(c).AuditLogEntry("Manage Commodity Suppliers", log);


                if (response.Success)
                {ContactsList.Clear();
                    var coResponse = await SaveCommodityOwner();
                    if (coResponse.ErrorInfo != "") responseMsg += coResponse.ErrorInfo + "\n";

                    var cpResponse = await SaveCommodityProducer();
                    if (cpResponse.ErrorInfo != "") responseMsg += cpResponse.ErrorInfo + "\n";
                    var enve = new VMContactItem();
                    var contact = new Contact(Guid.NewGuid());
                    contact.BusinessPhone = CommodityOwner.BusinessNumber;
                    contact.ContactClassification=ContactClassification.PrimaryContact;
                    contact.ContactOwnerMasterId = CommoditySupplier.Id;
                    contact.DateOfBirth = CommodityOwner.DateOfBirth;
                    contact.Email = CommodityOwner.Email;
                    contact.Fax = CommodityOwner.FaxNumber;
                    contact.Firstname = CommodityOwner.FirstName;
                    contact.HomePhone = CommodityOwner.PhoneNumber;
                    contact.JobTitle = "Farmer";
                    contact.Lastname = CommodityOwner.LastName;
                    contact.MStatus =CommodityOwner.MaritalStatus;
                    contact.PhysicalAddress = CommodityOwner.PhysicalAddress;
                    contact.PostalAddress = CommodityOwner.PostalAddress;
                    contact.MobilePhone = CommodityOwner.PhoneNumber;
                    contact.ContactType = SelectedContactOwnerType;
                    
                    enve.IsDirty = true;
                    enve.IsNew = true;
                    enve.Contact = contact;
                    ContactsList.Add(enve);

                    bool success = await SaveContacts(CommoditySupplier);

                    if (!coResponse.Success || !cpResponse.Success || !success)
                        response.Success = false;
                }

                MessageBox.Show(responseMsg, "Agrimanagr: Manage Farmer", MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (response.Success)
                    SendNavigationRequestMessage(
                        new Uri("views/admin/commodityowners/listcommodityowners.xaml", UriKind.Relative));
            }
        }
        protected async override void DeleteSelected()
        {
            ResponseBool response = new ResponseBool() { Success = false };
            
            if (MessageBox.Show("Are you sure you want to delete this Contact", "Agrimanagr:Delete Contact", MessageBoxButton.YesNo) == MessageBoxResult.No)
                return;
            using(var c=NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);

                if (SelectedContact == null) return;
                response = await _proxy.ContactDeleteAsync(SelectedContact.Id);
                if(response.Success)
                {
                    var contactEntity = Using<IContactRepository>(c).GetById(SelectedContact.Id);
                    Using<IContactRepository>(c).SetAsDeleted(contactEntity);
                }
                MessageBox.Show("Contact Has Been Deleted", "Agrimangr: Delete Contact", MessageBoxButton.OK,
                               MessageBoxImage.Information);
                    Load();
                

            }

        }
        protected override async void DeleteSelected()
        {
            if (
                      MessageBox.Show("Are you sure you want to delete this centre",
                                      "Agrimanagr: Activate Centre", MessageBoxButton.OKCancel) ==
                      MessageBoxResult.Cancel) return;
            using (var c = NestedContainer)
            {
                if (SelectedCentreItem.Centre._Status == EntityStatus.Active)
                {

                    if (Using<IMasterDataUsage>(c).CheckAgriCentreIsUsed(SelectedCentreItem.Centre, EntityStatus.Deleted))
                    {
                        MessageBox.Show(
                            "Centre " + SelectedCentreItem.Centre.Name +
                            " has been allocated to commodity producers. Unallocate first to delete this centre.",
                            "Agrimanagr: Delete Centre", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }

                ResponseBool response = new ResponseBool() {Success = false};
                if (SelectedCentreItem == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.CentreDeleteAsync(SelectedCentreItem.Centre.Id);

                if(response.Success)
                {
                    Using<ICentreRepository>(c).SetAsDeleted(SelectedCentreItem.Centre);
                }

                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Centre", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        private async void DeleteContact(VMContactItem contact)
        {
            using (StructureMap.IContainer c = NestedContainer)
            {
                ResponseBool response = null;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.ContactDeleteAsync(contact.Contact.Id);

                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Contacts", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                if (response.Success)
                    ContactsList.Remove(ContactsList.FirstOrDefault(n => n.Contact.Id == contact.Contact.Id));
            }
        }
        protected override async void DeleteSelected()
        {
            if (
                    MessageBox.Show("Are you sure you want to delete this weighing scale?",
                                    "Agrimanagr: Delete Weighing Scale", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.Cancel) return;

            using (var c = NestedContainer)
            {
                ResponseBool response = new ResponseBool() { Success = false };
                if (SelectedWeighingScale == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.EquipmentDeleteAsync(SelectedWeighingScale.WeighingScale.Id);
                if(response.Success)
                {
                    Using<IEquipmentRepository>(c).SetAsDeleted(SelectedWeighingScale.WeighingScale);
                    if (DeleteDeviceLocalSettings(SelectedWeighingScale.WeighingScale))
                        MessageBox.Show("A problem occurred while deleting the device local configuration settings.",
                                        "Device Local Configuration Settings Manager", MessageBoxButton.OK,
                                        MessageBoxImage.Exclamation);
                }
                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Weighing Scales", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        protected async override void ActivateSelected()
        {
            string action = SelectedCommodityProducerService.Status == EntityStatus.Active
                               ? "deactivate"
                               : "activate";
            if (MessageBox.Show("Are you sure you want to " + action + " this Commodity Producer Service ?",
                                "Agrimanagr: Manage Commodity Producer Service ", MessageBoxButton.YesNo) ==
                MessageBoxResult.No) return;

            using (var c = NestedContainer)
            {
                ResponseBool response = new ResponseBool() { Success = false };
                if (SelectedCommodityProducerService == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.CommodityProducerServiceActivateOrDeactivateAsync(SelectedCommodityProducerService.Id);

                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Commodity Producer Service ", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        private async void Save()
        {
            
            CommodityProducer commodityProducer;
            string responseMsg = string.Empty;
            var response = new ResponseBool {Success = false};
                using(var c=NestedContainer)
                {
                    commodityProducer = Using<ICommodityProducerRepository>(c).GetById(Id);
                    //commodityProducer.Code = Code;
                    if(commodityProducer==null)
                        commodityProducer = new CommodityProducer(Id);
                    
                    commodityProducer.CommodityProducerCentres.Clear();
                    commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                    commodityProducer.Code = Code;
                    commodityProducer.Name = Name;
                    commodityProducer.RegNo = RegistrationNumber;
                    commodityProducer.PhysicalAddress = PhysicalAddress;
                    commodityProducer.Description = Description;
                    commodityProducer.Acrage = Acerage;
                    commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                    commodityProducer._Status = EntityStatus.Active;

                var commoditySupplier = Using<ICommoditySupplierRepository>(c).GetById(SupplierId) as CommoditySupplier;
                if(commoditySupplier!=null)
                {
                    commodityProducer.CommoditySupplier = commoditySupplier;
                }

                if (!IsValid(commodityProducer)) return;
                
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await SaveCommodityProducer(commodityProducer);
                if (response.ErrorInfo != "")
                {
                    responseMsg += response.ErrorInfo + "\n";
                    if (!response.Success)
                    {
                        MessageBox.Show(response.ErrorInfo, "Agrimanager :" + PageTitle, MessageBoxButton.OK);
                        return;
                    }
                }
                
                if (!string.IsNullOrWhiteSpace(responseMsg)) //responseMsg.Equals(string.Empty))
                    if(IsEdit)
                    {
                        responseMsg = "Farmer Edited Successfully!";
                        IsEdit = false;
                    }
                    else
                    {
                        responseMsg = "Farmer Added Successfully!";
                    }
                MessageBox.Show(responseMsg, "Agrimanager :" + PageTitle, MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (response.Success)
                    SendNavigationRequestMessage(new Uri("Views/Admin/Producer/ListingMemberCommodityProducers.xaml",
                                                         UriKind.Relative));
            }
        }
        protected override async void DeleteSelected()
        {
            if (
                    MessageBox.Show("Are you sure you want to delete this container?",
                                    "Agrimanagr: Delete Container", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.Cancel) return;
            using (var c = NestedContainer)
            {
                if (SelectedContainer.Container._Status == EntityStatus.Active)
                {

                    if (Using<IMasterDataUsage>(c).CheckSourcingContainerIsUsed(SelectedContainer.Container))
                    {
                        MessageBox.Show(
                            "Container " + SelectedContainer.Container.Name +
                            " has dependencies. Deactivate or delete dependencies to continue.",
                            "Agrimanagr: Deactivate Container", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }

                ResponseBool response = new ResponseBool() {Success = false};
                if (SelectedContainer == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.ContainerDeleteAsync(SelectedContainer.Container.Id);
                if (response.Success)
                    Using<IEquipmentRepository>(c).SetAsDeleted(SelectedContainer.Container);
                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Containers", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        protected async override void ActivateSelected()
        {
            string action = SelectedCommodityOwner.CommoditySupplier._Status == EntityStatus.Active
                               ? "deactivate"
                               : "activate";
            if (
                    MessageBox.Show("Are you sure you want to " + action + " this commodity owner?",
                                    "Agrimanagr: Activate Commodity Owner", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.Cancel) return;

            using (var c = NestedContainer)
            {
                if(SelectedCommodityOwner.CommoditySupplier._Status == EntityStatus.Active)
                {
                    if(Using<IMasterDataUsage>(c).CommodityOwnerHasPurchases(SelectedCommodityOwner.CommoditySupplier))
                    {
                        MessageBox.Show(
                            "Commodity owner " + SelectedCommodityOwner.CommoditySupplier.Name +
                            " has purchases in the system and thus cannot be deactivated.",
                            "Agrimanagr: Deactivate Commodity Owner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }


                ResponseBool response = new ResponseBool() { Success = false };
                if (SelectedCommodityOwner == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.CommodityOwnerActivateOrDeactivateAsync(SelectedCommodityOwner.CommoditySupplier.Id);

                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Commodity Owner", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        private async Task<ResponseBool> SavePurchasingClerkCostCentre()
        {
            ResponseBool response = new ResponseBool {Success = false};
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);

                Guid ccId = User._Status == EntityStatus.New ? Guid.NewGuid() : User.CostCentre;
                PurchasingClerk pClerk =
                    Using<CostCentreFactory>(c).CreateCostCentre(ccId, CostCentreType.PurchasingClerk,
                                                                 Using<ICostCentreRepository>(c).GetById(
                                                                     GetConfigParams().CostCentreId)) as PurchasingClerk;
                pClerk.Name = User.Username;
                pClerk.CostCentreCode = Code;


                User.CostCentre = pClerk.Id;
                pClerk.User = User;
                pClerk.PurchasingClerkRoutes = GetRoutesAssigned(pClerk);

                PurchasingClerkItem pClerkItem = new PurchasingClerkItem()
                {
                    MasterId = pClerk.Id,
                    Name = pClerk.Name,
                    ParentCostCentreId = pClerk.ParentCostCentre.Id,
                    StatusId = (int)EntityStatus.Active,
                    CostCentreTypeId = (int)pClerk.CostCentreType,
                    CostCentreCode = pClerk.CostCentreCode
                };
                pClerkItem.UserItem = CreateUserItem(pClerk.Id);
                pClerkItem.PurchasingClerkRouteItems = pClerk.PurchasingClerkRoutes.Select(Map).ToList();

                AuditLogEntry = string.Format("Created purchasing clerk costcentre for user: {0};", User.Username);
                Using<IAuditLogWFManager>(c).AuditLogEntry("User Administration", AuditLogEntry);
                response = await _proxy.PurchasingCerkAddAsync(pClerkItem);
                if(response.Success)
                {
                   ChangeAllocation(pClerkItem);
                }
                MessageBox.Show(response.ErrorInfo, "Distributr: Manage purchasing clerk", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            return response;
        }
        private async void Save()
        {
            SetValues();
            if (!IsValid(User))
                return;
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = null;
                if (SelectedUserType == UserType.None)
                {
                    MessageBox.Show(GetLocalText("sl.user.edit.validate.usertype") /*"Select user type"*/,
                                    "Distributr: Invalid Field(s)", MessageBoxButton.OK);
                    return;
                }

                if (User.UserType == UserType.PurchasingClerk)
                {
                    response = await SavePurchasingClerkCostCentre();
                    if (!response.Success) return;
                }
                else
                {
                    var userItem = CreateUserItem(GetConfigParams().CostCentreId);

                    response = await _proxy.UserAddAsync(userItem);
                    AuditLogEntry = string.Format("Created New User: {0}; Code: {1}; And User Type", userItem.Username,
                                                  SelectedUserType);
                    Using<IAuditLogWFManager>(c).AuditLogEntry("User Administration", AuditLogEntry);

                    MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Users", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                if (response.Success)
                {
                    if (await SaveContacts(User))
                    {
                        ConfirmNavigatingAway = false;
                        SendNavigationRequestMessage(new Uri(@"\views\admin\users\listusers.xaml",
                                                                            UriKind.Relative));
                    }
                }
            }
        }
示例#13
0
        protected override async void ActivateSelected()
        {
            string action = SelectedStore.Store._Status == EntityStatus.Active
                              ? "deactivate"
                              : "activate";
            if (
                    MessageBox.Show("Are you sure you want to " + action + " this store?",
                                    "Agrimanagr: Activate Store", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.Cancel) return;
            using (var c = NestedContainer)
            {
                if (SelectedStore.Store._Status == EntityStatus.Active)
                {
                    if (Using<IMasterDataUsage>(c).CheckStoreIsUsed(SelectedStore.Store, EntityStatus.Inactive))
                    {
                        MessageBox.Show(
                            "Store " + SelectedStore.Store.Name +
                            " has been used in a transaction. Deactivate or delete dependencies to continue.",
                            "Agrimanagr: Deactivate Store", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }

                ResponseBool response = new ResponseBool() {Success = false};
                if (SelectedStore == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.StoreActivateOrDeactivateAsync(SelectedStore.Store.Id);

                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Store", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
示例#14
0
        private async void Save()
        {
            Centre.CenterType = SelectedCentreType;
            Centre.Route = SelectedRoute;
            if (!IsValid())
                return;
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = null;

                response = await _proxy.CentreAddAsync(Centre);
                string log = string.Format("Created new centre: {0}; Code: {1}; And centre Type {2}", Centre.Name,
                                           Centre.Code,
                                           SelectedCentreType.Name);
                Using<IAuditLogWFManager>(c).AuditLogEntry("User Administration", log);

                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Centres", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                if (response.Success)
                {
                    SendNavigationRequestMessage(new Uri("views/admin/centres/listcentres.xaml", UriKind.Relative));
                }
            }
        }
        protected async override void DeleteSelected()
        {
            if (
               MessageBox.Show("Are you sure you want to delete this Infection?",
                                    "Agrimanagr: Delete Infection", MessageBoxButton.YesNo) ==
                    MessageBoxResult.No) return;

            using (var c = NestedContainer)
            {
                var response = new ResponseBool() { Success = false };
                if (SelectedInfection == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.InfectionDeleteAsync(SelectedInfection.Id);
                if (response.Success)
                {
                    var infection = Using<IInfectionRepository>(c).GetById(SelectedInfection.Id);
                    Using<IInfectionRepository>(c).SetAsDeleted(infection);
                    MessageBox.Show(response.ErrorInfo, "Agrimangr:Manage Infection", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                    
            }
        }
        private async void Save()
        {
            CommodityOwner commodityOwner;
            string responseMsg = string.Empty;
            var response = new ResponseBool {Success = false};


            if (DateTime.Now.Year - DateOfBirth.Year < 18)
            {
                MessageBox.Show("Farmer must be over 18 years old.", "Agrimanagr: Farmer Management",
                                MessageBoxButton.OK);
                return;
            }

            if (string.IsNullOrEmpty(Surname) || string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(IdNumber) || string.IsNullOrEmpty(PinNumber) || string.IsNullOrEmpty(SelectedCommodityOwnerTypePropertyName) || string.IsNullOrEmpty(PostalAddress) || string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(PhoneNumber) || string.IsNullOrEmpty(BusinessNumber) || string.IsNullOrEmpty(PhysicalAddress))
            {
                MessageBox.Show("Please fill in all the mandatory fields.", "Agrimanagr: Farmer Management",
                                MessageBoxButton.OK);
                return;
            }
                using (var c = NestedContainer)
                {
                    commodityOwner = Using<ICommodityOwnerRepository>(c).GetById(Id);
                    if(commodityOwner==null)
                    {
                        commodityOwner = new CommodityOwner(Id);
                    }
                    commodityOwner.Surname = Surname;
                    commodityOwner.FirstName = FirstName;
                    commodityOwner.Code = Code;
                    commodityOwner.IdNo = IdNumber;
                    commodityOwner.PinNo = PinNumber;
                    commodityOwner.MaritalStatus = SelectedMaritalStatus;
                    commodityOwner.CommodityOwnerType = SelectedCommodityOwnerType;
                    commodityOwner.PhysicalAddress = PhysicalAddress;
                    commodityOwner.PhoneNumber = PhoneNumber;
                    commodityOwner.BusinessNumber = BusinessNumber;
                    commodityOwner.OfficeNumber = OfficeNumber;
                    commodityOwner.FaxNumber = FaxNumber;
                    commodityOwner.Email = Email;
                   
                    commodityOwner.DateOfBirth = DateOfBirth;
                    commodityOwner.Description = Description;
                    commodityOwner.PostalAddress = PostalAddress;
                    commodityOwner._Status = EntityStatus.Active;
                
                var commoditySupplier = Using<ICommoditySupplierRepository>(c).GetById(SupplierId) as CommoditySupplier;
                if (commoditySupplier != null)
                {
                    commodityOwner.CommoditySupplier = commoditySupplier;
                }


                //if (IsValid(commodityOwner))
                //{
                    _proxy = Using<IDistributorServiceProxy>(c);
                    response = await SaveCommodityOwner(commodityOwner);
                    if (response.ErrorInfo != "")
                        responseMsg += response.ErrorInfo + "\n";
                //}

                if (response.Success&& string.IsNullOrEmpty(response.ErrorInfo))
                {
                     responseMsg = "Farmer Added Successfully!";
                    MessageBox.Show(responseMsg, "Agrimanager :" + PageTitle, MessageBoxButton.OK,
                               MessageBoxImage.Information);
                    SendNavigationRequestMessage(new Uri("Views/Admin/Owner/ListingMemberCommodityOwner.xaml", UriKind.Relative));
                }
                else
                {
                    MessageBox.Show(responseMsg, "Agrimanager :" + PageTitle, MessageBoxButton.OK,
                               MessageBoxImage.Information);
                }
                   
            }
        }
        private async void Save()
        {
              var commodityOwner =new CommodityOwner(CommodityOwnerId);
              var commoditySupplier=new CommoditySupplier(Id);
              var  commodityProducer = new CommodityProducer(CommodityProducerId);
              var contact = new Contact(ContactId);

         using (var c = NestedContainer)
            {
                commodityOwner.Code = OwnerCode;
                if (string.IsNullOrEmpty(commodityOwner.Code))
                {
                    MessageBox.Show("Farmer Code is a Required Field", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                    return;

                }
                commodityOwner.Surname = Surname;
                commodityOwner.FirstName = FirstName;
                commodityOwner.LastName = MiddleName;
                commodityOwner.IdNo = IdNumber;
                commodityOwner.PinNo = PinNumber;
                //CommodityOwner.Gender =;
                commodityOwner.PhysicalAddress = PhysicalAddress;
                commodityOwner.PostalAddress = PostalAddress;
                commodityOwner.Email = Email;
                commodityOwner.PhoneNumber = PhoneNumber;
                commodityOwner.BusinessNumber = BusinessNumber;
                commodityOwner.FaxNumber = FaxNumber;
                commodityOwner.OfficeNumber = OfficeNumber;
                commodityOwner.Description = Description;
                commodityOwner.DateOfBirth = DateOfBirth;
                commodityOwner.CommoditySupplier = commoditySupplier;
                commodityOwner._Status = EntityStatus.Active;
                if (DateTime.Now.Year - DateOfBirth.Year < 18)
                    {
                        MessageBox.Show("Farmer must be over 18 years old.", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                        return;
                    }
            
                commodityOwner.MaritalStatus = SelectedMaritalStatus;
                commodityOwner.CommodityOwnerType = SelectedCommodityOwnerType;

                commoditySupplier.JoinDate = DateTime.Now.Date;
                commoditySupplier.AccountName = AccountName;
                commoditySupplier.AccountNo = AccountNumber;

                commoditySupplier._Status = EntityStatus.Active;
                commoditySupplier.PinNo = PinNumber;
                commoditySupplier.BankId = SelectedBank.Id;
                commoditySupplier.BankBranchId = SelectedBankBranch.Id;
                commoditySupplier.CommoditySupplierType = SelectedCommoditySupplierType;
                commoditySupplier.CostCentreCode = CostCenterCode;
                commoditySupplier.Name = AccountFullName;
                    var config = Using<IConfigService>(c).Load();
                    commoditySupplier.ParentCostCentre = new CostCentreRef {Id = config.CostCentreId};

                if (!IsValid(commoditySupplier))
                    return;

                commodityProducer.CommoditySupplier = commoditySupplier;
                commodityProducer._SetStatus(EntityStatus.Active);
                commodityOwner.BusinessNumber = BusinessNumber;
               if (!IsValid(commodityOwner)) return;

                commodityProducer.CommodityProducerCentres.Clear();
             
             
                commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                commodityProducer.Code = FarmCode;
                if (string.IsNullOrEmpty(commodityProducer.Code))
                {
                    MessageBox.Show("Farm Code is a Required Field", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                    return;
                }
                commodityProducer.Acrage = Acerage;
                commodityProducer.Name = FarmName;
                commodityProducer._Status = EntityStatus.Active;
                commodityProducer.RegNo = FarmRegistrationNo;
                commodityProducer.PhysicalAddress = FarmPhysicalAddress;
                commodityProducer.Description = FarmDescription;
                commodityProducer.CommoditySupplier = commoditySupplier;


                contact.BusinessPhone = BusinessNumber;
                contact.Email = Email;
                contact.ContactOwnerMasterId = commoditySupplier.Id;
                contact.Firstname = AccountFullName;
                contact.PostalAddress = PostalAddress;
                contact.MobilePhone = PhoneNumber;
                contact.PhysicalAddress = PhysicalAddress;
                contact.ContactOwnerType=ContactOwnerType.CommoditySupplier;

                if (!IsValid() || !IsValid(commodityProducer)) return;


                   string responseMsg = "";
                   _proxy = Using<IDistributorServiceProxy>(c);
                   var mapper = Using<IMasterDataToDTOMapping>(c);
                    var commoditySupplierdto = mapper.Map(commoditySupplier);
                    ResponseBool response = await _proxy.CommoditySupplierAddAsync(commoditySupplierdto);
                    responseMsg += response.ErrorInfo + "\n";

                    string log = string.Format("Created commodity supplier: {0}; Code: {1}; And Type {2}",
                                               commoditySupplier.Name,
                                               commoditySupplier.CostCentreCode, commoditySupplier.CommoditySupplierType);
                    Using<IAuditLogWFManager>(c).AuditLogEntry("Manage Commodity Suppliers", log);


                    if (response.Success)
                    {
                        ContactsList.Clear();
                        var coResponse = await SaveCommodityOwner(commodityOwner);
                        if (coResponse.ErrorInfo != "") responseMsg += coResponse.ErrorInfo + "\n";

                        var contactResponse = await SaveSupplierContact(contact);
                        if (contactResponse.ErrorInfo != "") responseMsg += contactResponse.ErrorInfo + "\n";

                        var cpResponse = await SaveCommodityProducer(commodityProducer);
                        if (cpResponse.ErrorInfo != "") responseMsg += cpResponse.ErrorInfo + "\n";

                       

                        if (!coResponse.Success || !cpResponse.Success)
                            response.Success = false;
                    }
                    if (response.Success)
                    {
                          responseMsg = "Farmer Successfully Added ";
                        MessageBox.Show(responseMsg, "Agrimanagr: Manage Farmer", MessageBoxButton.OK,
                                    MessageBoxImage.Information);

                         SendNavigationRequestMessage(
                            new Uri("views/admin/Supplier/ListOfSuppliers.xaml", UriKind.Relative));
                    }
                    else
                    {
                        MessageBox.Show(responseMsg, "Agrimanagr: Manage Farmer", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    }

            
                       
            }
        }
        protected async override void DeleteSelected()
        {
            if (
               MessageBox.Show("Are you sure you want to delete this Commodity Producer Service?",
                                    "Agrimanagr: Delete Commodity Producer Service", MessageBoxButton.YesNo) ==
                    MessageBoxResult.No) return;

            using (var c = NestedContainer)
            {
                if (SelectedCommodityProducerService.Status == EntityStatus.Active)
                {

                    var service = Using<IServiceRepository>(c).GetById(SelectedCommodityProducerService.Id);


                }
                var response = new ResponseBool() { Success = false };
                if (SelectedCommodityProducerService == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.CommodityProducerServiceDeleteAsync(SelectedCommodityProducerService.Id);
                if (response.Success)
                {
                    var commodityProducerService =Using<IServiceRepository>(c).GetById(SelectedCommodityProducerService.Id);
                    Using<IServiceRepository>(c).SetAsDeleted(commodityProducerService);
                    MessageBox.Show(response.ErrorInfo, "Agrimangr:Manage Commodity Producer Service", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                    
            }
        }
        protected async override void DeleteSelected()
        {
            if (
               MessageBox.Show("Are you sure you want to delete this commodity Owner?",
                                    "Agrimanagr: Delete Commodity Owner", MessageBoxButton.YesNo) ==
                    MessageBoxResult.No) return;

            using (var c = NestedContainer)
            {
                if (SelectedCommodityOwner.Status == EntityStatus.Active)
                {

                    var commodityOwner = Using<ICommodityOwnerRepository>(c).GetById(SelectedCommodityOwner.Id);

                    if (Using<IMasterDataUsage>(c).CommodityOwnerHasProducers(commodityOwner))
                    {
                        MessageBox.Show(
                            "Commodity Owner " + SelectedCommodityOwner.FirstName +
                            " has purchases in the system and thus cannot be deleted.",
                            "Agrimanagr: Delete Commodity Owner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
                var response = new ResponseBool() { Success = false };
                if (SelectedCommodityOwner == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.CommodityOwnerDeleteAsync(SelectedCommodityOwner.Id);
                if (response.Success)
                {
                    var commodityowner = Using<ICommodityOwnerRepository>(c).GetById(SelectedCommodityOwner.Id);
                    Using<ICommodityOwnerRepository>(c).SetAsDeleted(commodityowner);
                    MessageBox.Show(response.ErrorInfo, "Agrimangr:Manage Commodity Owner", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    Load();
                }
                    
            }
        }
        protected override async void ActivateSelected()
        {
            using (var c = NestedContainer)
            {


                string action = SelectedWeighingScale.WeighingScale._Status == EntityStatus.Active
                             ? "deactivate"
                             : "activate";
                if (
                        MessageBox.Show("Are you sure you want to " + action + " this weighing scale?",
                                        "Agrimanagr: Activate Container", MessageBoxButton.OKCancel) ==
                        MessageBoxResult.Cancel) return;

                ResponseBool response = new ResponseBool() { Success = false };
                if (SelectedWeighingScale == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.EquipmentActivateOrDeactivateAsync(SelectedWeighingScale.WeighingScale.Id);

                if(response.Success)
                {
                    if (action == "deactivate")
                    {
                        if (DeleteDeviceLocalSettings(SelectedWeighingScale.WeighingScale))
                            MessageBox.Show("A problem occurred while deleting the device local configuration settings.",
                                            "Device Local Configuration Settings Manager", MessageBoxButton.OK,
                                            MessageBoxImage.Exclamation);
                    }
                    
                }
                

                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Weighing Scales", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        protected async override void DeleteSelected()
        {
            if (SelectedContact == null) return;
            using (StructureMap.IContainer c = NestedContainer)
            {
                ResponseBool response = null;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.ContactDeleteAsync(SelectedContact.Contact.Id);

                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Contacts", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                if (response.Success)
                    ContactsList.Remove(ContactsList.FirstOrDefault(n => n.Contact.Id == SelectedContact.Contact.Id));
            }
        }
示例#22
0
        public async void Save()
        {
            if (!IsValid())
                return;
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = null;
                response = await _proxy.VehicleAddAsync(Vehicle);

                string log = string.Format("Created vehicle: {0}; Code: {1};", Vehicle.Name,
                                           Vehicle.Code);
                Using<IAuditLogWFManager>(c).AuditLogEntry("Vehicle Management", log);

                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Vehicles", MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (response.Success)
                {
                    SendNavigationRequestMessage(
                        new Uri("views/admin/vehicles/listvehicles.xaml", UriKind.Relative));
                }
            }
        }
示例#23
0
        protected override async void DeleteSelected()
        {
            if (
                MessageBox.Show("Are you sure you want to delete this vehicle?",
                                "Agrimanagr: Delete Vehicle", MessageBoxButton.OKCancel) ==
                MessageBoxResult.Cancel) return;
            using (var c = NestedContainer)
            {
                if (Using<IMasterDataUsage>(c).CheckVehicleIsUsed(SelectedVehicle.Vehicle, EntityStatus.Deleted))
                {
                    MessageBox.Show(
                        "Vehicle " + SelectedVehicle.Vehicle.Name +
                        " has been used in a transaction. Delete dependencies to continue.",
                        "Agrimanagr: Delete Vehicle", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                ResponseBool response = new ResponseBool() {Success = false};
                if (SelectedVehicle == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await _proxy.VehicleDeleteAsync(SelectedVehicle.Vehicle.Id);
                if (response.Success)
                    Using<IVehicleRepository>(c).SetAsDeleted(SelectedVehicle.Vehicle);
                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Vehicles", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
        protected async override void ActivateSelected()
        {
            string action = SelectedContact.Status == EntityStatus.Active
                               ? "deactivate"
                               : "activate";
            if (MessageBox.Show("Are you sure you want to " + action + " this Contact?",
                                    "Agrimanagr: " + action + " Contact", MessageBoxButton.YesNo) ==
                    MessageBoxResult.No) return;

            using (var c = NestedContainer)
            {
                
                ResponseBool response = new ResponseBool() { Success = false };
                if (SelectedContact == null) return;
                _proxy = Using<IDistributorServiceProxy>(c);

                if (action == "activate")
                {
                    response = await _proxy.ContactActivateAsync(SelectedContact.Id);
                }
                else if (action == "deactivate")
                {
                    response = await _proxy.ContactDeactivateAsync(SelectedContact.Id);
                }
                MessageBox.Show(response.ErrorInfo, "Agrimangr: Manage Contact", MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (MessageBox.Show("Contact has been "+action+"d", "Agrimangr: "+action+" Contact", MessageBoxButton.OK,
                              MessageBoxImage.Information) == MessageBoxResult.OK)
                    Load();
            }
        }
示例#25
0
        public async void Save()
        {
            Store.Contact = new List<Contact>();
            Store.Contact.AddRange(ContactsList.Select(n => n.Contact));
            if (!IsValid())
                return;
            if (Store.Name == null )
            {
                MessageBox.Show( "Name field is Empty","Agrimanagr: Manage Stores", MessageBoxButton.OK,MessageBoxImage.Error);
                return;
            }
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = null;
                response = await _proxy.StoreAddAsync(Store);
                string log = string.Format("Created store: {0}; Code: {1};", Store.Name,
                                           Store.CostCentreCode);
                Using<IAuditLogWFManager>(c).AuditLogEntry("Store Management", log);

                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage Stores", MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (response.Success)
                {
                    SendNavigationRequestMessage(
                        new Uri("views/admin/stores/liststores.xaml", UriKind.Relative));
                }
            }
        }