protected void EditContact(VMContactItem contactItem, MasterEntity entity)
 {
     using(var c = NestedContainer)
     {
         Contact contact = null;
         if (Using<IEditContactModal>(c).AddUserContact(contactItem.Contact, out contact))
             AddContactToList(entity, contact);
     }
 }
        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));
            }
        }
        private void AddContactToList(MasterEntity entity, Contact contact)
        {
            VMContactItem contactItem = new VMContactItem {IsNew = contact._Status == EntityStatus.New, IsDirty = true};
            if (contact.Id == Guid.Empty)
            {
                contact.Id = Guid.NewGuid();
                contact.ContactOwnerType = ContactOwnerType.User;
                if (contact.ContactClassification == ContactClassification.None)
                    contact.ContactClassification = ContactClassification.SecondaryContact;

                if(ContactsList.All(n => n.Contact.ContactClassification != ContactClassification.PrimaryContact))
                    contact.ContactClassification = ContactClassification.PrimaryContact;
            }

            if (contact.ContactClassification == ContactClassification.PrimaryContact)
            {
                foreach (var cont in ContactsList.Where(n => n.IsPrimaryContact))
                {
                    cont.Contact.ContactClassification = ContactClassification.SecondaryContact;
                    cont.IsDirty = true;
                }
            }

            var existing = ContactsList.FirstOrDefault(n => n.Contact.Id == contact.Id);
            if (existing != null)
                ContactsList.Remove(existing);

            contact.ContactOwnerMasterId = entity.Id;
            contactItem.Contact = contact;

            ContactsList.Add(contactItem);
        }
 protected abstract void EditContact(VMContactItem contactItem);
 protected override void EditContact(VMContactItem contactItem)
 {
     base.EditContact(contactItem, CommoditySupplier);
 }
        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 Task<bool> SaveContacts(Guid entityId, VMContactItem item)
        {
            using (var c = NestedContainer)
            {
                _proxy = Using<IDistributorServiceProxy>(c);
                ResponseBool response = null;
                var itemsToSave = new List<ContactItem>();
                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 = entityId,
                        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);

                response = await _proxy.ContactsAddAsync(itemsToSave.ToList());
                MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage contacts", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                return response.Success;
            }
        }
        private VMContactItem AddContactToList(Guid entityId, Contact contact)
        {
            VMContactItem contactItem = new VMContactItem();
            if (contact.Id == Guid.Empty)
            {
                contact.Id = Guid.NewGuid();
                contactItem.IsNew = true;
                contact.ContactOwnerType = ContactOwnerType.User;
            }

            if (contact.ContactClassification == ContactClassification.PrimaryContact)
            {
                foreach (var cont in ContactsList.Where(n => n.IsPrimaryContact))
                {
                    cont.Contact.ContactClassification = ContactClassification.SecondaryContact;
                    cont.IsDirty = true;
                }
            }

            var existing = ContactsList.FirstOrDefault(n => n.Contact.Id == contact.Id);
            if (existing != null)
                ContactsList.Remove(existing);

            contact.ContactOwnerMasterId = entityId;
            contactItem.Contact = contact;
            contactItem.IsDirty = true;

            ContactsList.Add(contactItem);
            return contactItem;
        }
Пример #9
0
 protected override void EditContact(VMContactItem contactItem)
 {
     base.EditContact(contactItem, User);
 }