コード例 #1
0
        public async Task<ResponseBool> ContactUpdateAsync(ContactItem contactItem)
        {
            ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };

            string url = string.Format("api/distributorservices/contactupdate");
            var httpClient = setupHttpClient();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                var response = await httpClient.PostAsJsonAsync(url, contactItem);
                _response = await response.Content.ReadAsAsync<ResponseBool>();


            }
            catch (Exception ex)
            {
                _log.Error("Failed to update contacts", ex);
                _response.ErrorInfo = "Error: An error occurred when saving the contact.\n" +
                                      ex.Message;
            }
            return _response;
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        private ContactItem Map(Contact contact)
        {
            var item = new ContactItem
                {

                    MasterId = contact.Id,
                    Firstname = contact.Firstname,
                    BusinessPhone = contact.BusinessPhone,
                    Fax = contact.Fax,
                    PhysicalAddress = contact.PhysicalAddress,
                    PostalAddress = contact.PostalAddress,
                    HomePhone = contact.HomePhone,
                    MobilePhone = contact.MobilePhone,
                    Email = contact.Email,
                    IsNew = true,
                    ContactOwnerMasterId = contact.ContactOwnerMasterId,


                };
            return item;
        }
コード例 #4
0
 public Task<ResponseBool> AgriUserAddAsync(UserItem user, ContactItem contact, List<RouteItem> routes)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
        private async Task<ResponseBool> SaveSupplierContact(Contact contact)
        {
             var contactItems = new List<ContactItem>();
            var contactItem = new ContactItem();
            string responseMsg = string.Empty;
            var response = new ResponseBool { Success = false };


            using(var c=NestedContainer)
            {
              
                contactItem.MasterId =contact.Id;
                contactItem.Firstname = contact.Firstname;
                contactItem.BusinessPhone = contact.BusinessPhone;
                contactItem.ContactOwnerMasterId =contact.ContactOwnerMasterId;
                contactItem.MobilePhone = contact.MobilePhone;
                contactItem.ContactOwnerType = contact.ContactOwnerType;
                contactItem.Email = contact.Email;
                contactItem.PostalAddress = contact.PostalAddress;
                contactItem.PhysicalAddress = contact.PhysicalAddress;
                contactItem.IsNew = true;
            }
            
            contactItems.Add(contactItem);

           using(var c=NestedContainer)
           {
               response = await Using<IDistributorServiceProxy>(c).ContactsAddAsync(contactItems.ToList());
               return response;
           }
        }
コード例 #6
0
      async void Save()
      {
          if (!IsValid())
              return;

          using (StructureMap.IContainer c = NestedContainer)
          {

              ResponseBool response = null;
              var proxy = Using<IDistributorServiceProxy>(c);

              ContactItem contactItem = null;
              var contactItems = new List<ContactItem>();

              if (Id == Guid.Empty)
              {
                  #region contactItem = new ContactItem
        
                  if (SelectedContactOwner != null)
                  {
                      var masterid=
                          contactItem = new ContactItem
                          {
                              MasterId = Guid.NewGuid(),
                              DateOfBirth = DateOfBirth,
                              MaritalStatusMasterId = (int)SelectedMaritalStatus,
                              BusinessPhone = BusinessPhone,
                              ChildrenNames = ChildrenNames,
                              City = City,
                              Company = Company,
                              ContactClassification = (int)SelectedContactClassification,
                              ContactOwnerType = SelectedContactOwnerType,
                              ContactTypeMasterId = SelectedContactType.Id,
                              ContactOwnerMasterId = SelectedContactOwner.Id,
                              DateCreated = DateTime.Now,
                              Email = Email,
                              Fax = Fax,
                              Firstname = FirstName,
                              HomePhone = HomePhone,
                              HomeTown = HomeTown,
                              JobTitle = JobTitle,
                              Lastname = LastName,
                              MobilePhone = MobilePhone,
                              PhysicalAddress = PhysicalAddress,
                              PostalAddress = PostalAddress,
                              SpouseName = SpouseName,
                              WorkExtPhone = WorkExtensionPhone,
                              DateLastUpdated = DateTime.Now,
                              StatusId = (int)EntityStatus.Active,
                              IsNew = true
                          };
                  }

                  #endregion

                  contactItems.Add(contactItem);
                  string AuditLogEntry = string.Format("Created New Contact: {0}; Contact Owner: ", FirstName + " " + LastName);
                  Using<IAuditLogWFManager>(c).AuditLogEntry("Contacts Administration", AuditLogEntry);
              }
              else
              {
                  #region contactItem = new ContactItem

                  contactItem = new ContactItem
                  {
                      MasterId = Id,
                      DateOfBirth = DateOfBirth,
                      MaritalStatusMasterId = (int)SelectedMaritalStatus,
                      BusinessPhone = BusinessPhone,
                      ChildrenNames = ChildrenNames,
                      City = City,
                      Company = Company,
                      ContactClassification = (int)SelectedContactClassification,
                      ContactOwnerType = SelectedContactOwnerType,
                      ContactTypeMasterId = SelectedContactType.Id,
                      ContactOwnerMasterId = SelectedContactOwner.Id,
                      DateCreated = DateTime.Now,
                      Email = Email,
                      Fax = Fax,
                      Firstname = FirstName,
                      HomePhone = HomePhone,
                      HomeTown = HomeTown,
                      JobTitle = JobTitle,
                      Lastname = LastName,
                      MobilePhone = MobilePhone,
                      PhysicalAddress = PhysicalAddress,
                      PostalAddress = PostalAddress,
                      SpouseName = SpouseName,
                      WorkExtPhone = WorkExtensionPhone,
                      DateLastUpdated = DateTime.Now,
                      StatusId = (int)EntityStatus.Active,
                      IsNew = false
                  };

                  #endregion

                  contactItems.Add(contactItem);

                  string AuditLogEntry = string.Format("Updated Contact: {0}; Contact Owner: ", FirstName + " " + LastName);
                  Using<IAuditLogWFManager>(c).AuditLogEntry("Contacts Administration", AuditLogEntry);
              }


              if (contactItem.ContactClassification == (int)ContactClassification.PrimaryContact)
              {
                  var existingPrimConts =
                      Using<IContactRepository>(c).GetByContactsOwnerId(SelectedContactOwner.Id).Where(
                          n => n.ContactClassification == ContactClassification.PrimaryContact);
                  foreach (var item in existingPrimConts)
                  {
                      #region var existing = new ContactItem

                      var existing = new ContactItem
                      {
                          MasterId = item.Id,
                          DateOfBirth = item.DateOfBirth,
                          MaritalStatusMasterId = (int)SelectedMaritalStatus,
                          BusinessPhone = item.BusinessPhone,
                          ChildrenNames = item.ChildrenNames,
                          City = item.City,
                          Company = item.Company,
                          ContactClassification = (int)ContactClassification.SecondaryContact,
                          DateCreated = item._DateCreated,
                          Email = item.Email,
                          Fax = item.Fax,
                          Firstname = item.Firstname,
                          HomePhone = item.HomePhone,
                          HomeTown = item.HomeTown,
                          JobTitle = item.JobTitle,
                          Lastname = item.Lastname,
                          MobilePhone = item.MobilePhone,
                          PhysicalAddress = item.PhysicalAddress,
                          PostalAddress = item.PostalAddress,
                          SpouseName = item.SpouseName,
                          WorkExtPhone = item.WorkExtPhone,
                          DateLastUpdated = DateTime.Now,
                          StatusId = (int)EntityStatus.Active,
                          ContactOwnerMasterId = item.ContactOwnerMasterId,
                          ContactOwnerType = item.ContactOwnerType,
                          ContactTypeMasterId = item.ContactType != null ? item.ContactType.Id : Guid.Empty,
                          IsNew = false
                      };

                      #endregion

                      string AuditLogEntry = string.Format("Updated Contact: {0}; Contact Owner: ",
                                                     FirstName + " " + LastName);
                      Using<IAuditLogWFManager>(c).AuditLogEntry("Contacts Administration", AuditLogEntry);

                      contactItems.Add(existing);
                  }
              }

              response = await proxy.ContactsAddAsync(contactItems.ToList());
              MessageBox.Show(response.ErrorInfo, "Distributr: Manage contacts", MessageBoxButton.OK,
                              MessageBoxImage.Information);
              if (response.Success)
              {
                  ConfirmNavigatingAway = false;
                  SendNavigationRequestMessage(new Uri("/views/administration/contacts/listcontacts.xaml",
                                                       UriKind.Relative));
              }
          }
      }
コード例 #7
0
        private async void Save()
        {
            var contactItems = new List<ContactItem>();
            var contactItem = new ContactItem();
            string responseMsg = string.Empty;
            var response = new ResponseBool { Success = false };


            using(var c=NestedContainer)
            {
                var contact = Using<IContactRepository>(c).GetById(Id);
                if(contact==null)
                {
                    Id = Guid.NewGuid();
                   contact=new Contact(Id);
                }
            
            
                contactItem.MasterId =Id;
                contactItem.BusinessPhone = BusinessNumber;
                contactItem.ContactClassification = (int) SelectedContactClassification;
                contactItem.ContactOwnerMasterId = SupplierId;
                contactItem.ContactTypeMasterId = SelectedContactType!=null?SelectedContactType.Id:Guid.Empty;
                contactItem.Email = Email;
                contactItem.Fax = FaxNumber;
                contactItem.Firstname = FirstName;
                contactItem.HomePhone = OfficeNumber;
                contactItem.Lastname = LastName;
                contactItem.MobilePhone = MobileNumber;
                contactItem.PhysicalAddress = PhysicalAddress;
                contactItem.PostalAddress = PostalAddress;
                contactItem.StatusId = (int) EntityStatus.Active;
                contactItem.IsNew = true;
            }
            
            contactItems.Add(contactItem);

           using(var c=NestedContainer)
           {
               response = await Using<IDistributorServiceProxy>(c).ContactsAddAsync(contactItems.ToList());
               MessageBox.Show(response.ErrorInfo, "Agrimanagr: Manage contacts", MessageBoxButton.OK,
                               MessageBoxImage.Information);
           }
           if(response.Success)
               SendNavigationRequestMessage(new Uri("/Views/Admin/SupplierContacts/ListingSupplierContacts.xaml", UriKind.Relative));
        }
コード例 #8
0
        private void _ContactUpdate(ContactItem contactItem)
        {
            Contact contact = _contactRepository.GetById(contactItem.MasterId);

            contact.BusinessPhone = contactItem.BusinessPhone;
            contact.ChildrenNames = contactItem.ChildrenNames;
            contact.City = contactItem.City;
            contact.Company = contactItem.Company;
            contact.ContactClassification = (ContactClassification)contactItem.ContactClassification;
            contact.ContactOwnerType = (ContactOwnerType)contactItem.ContactOwnerType;
            contact.ContactOwnerMasterId = contactItem.ContactOwnerMasterId;
            contact.DateOfBirth = contactItem.DateOfBirth;
            contact.Email = contactItem.Email;
            contact.Fax = contactItem.Fax;
            contact.Firstname = contactItem.Firstname;
            contact.HomePhone = contactItem.HomePhone;
            contact.HomeTown = contactItem.HomeTown;
            contact.JobTitle = contactItem.JobTitle;
            contact.Lastname = contactItem.Lastname;
            contact.MobilePhone = contactItem.MobilePhone;
            contact.PhysicalAddress = contactItem.PhysicalAddress;
            contact.PostalAddress = contactItem.PostalAddress;
            contact.SpouseName = contactItem.SpouseName;

            contact.WorkExtPhone = contactItem.WorkExtPhone;
            contact.MStatus = (MaritalStatas) contactItem.MaritalStatusMasterId;
            if (contactItem.ContactTypeMasterId != Guid.Empty)
                contact.ContactType = _contactTypeRepository.GetById(contactItem.ContactTypeMasterId);
            else
                contact.ContactType = null;

            _contactRepository.Save(contact);



        }
コード例 #9
0
 public HttpResponseMessage ContactUpdate(ContactItem contactItem)
 {
     var response = new ResponseBool { Success = false };
     try
     {
         _ContactUpdate(contactItem);
         response.ErrorInfo = "Successfully saved contacts";
         response.Success = true;
     }
     catch (DomainValidationException dve)
     {
         string errorMsg = dve.ValidationResults.Results.Aggregate("Error: Invalid contact fields.\n",
                                                                   (current, msg) =>
                                                                   current + ("\t- " + msg.ErrorMessage + "\n"));
         response.ErrorInfo = errorMsg;
         _log.Error(errorMsg, dve);
     }
     catch (Exception ex)
     {
         response.ErrorInfo = "Error: An error occurred when saving the contact information.";
         _log.Error("Error: An error occurred when saving the contact information.", ex);
     }
     return Request.CreateResponse(HttpStatusCode.OK, response);
 }