Example #1
0
        public void ShouldSetValueOfUnderlyingModelProperty()
        {
            var wrapper = new ContactWrapper(_contact);

            wrapper.FirstName = "Julia";
            Assert.AreEqual("Julia", _contact.FirstName);
        }
        public async Task LoadAsync(int?contactId)
        {
            var contact = contactId.HasValue
                ? await _contactRepository.GetByIdAsync(contactId.Value)
                : CreateNewContact();

            Contact = new ContactWrapper(contact);
            Contact.PropertyChanged += (s, e) =>
            {
                if (!HasChanges)
                {
                    HasChanges = _contactRepository.HasChanges();
                }

                if (e.PropertyName == nameof(Contact.HasErrors))
                {
                    ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();
                }
            };

            if (contact.Id == 0)
            {
                //Little trick to trigger the validation
                contact.Name = "";
            }

            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();
        }
        /// <summary>
        /// Edits a contact.
        /// </summary>
        /// <param name="model">The contact.</param>
        /// <param name="token">The token.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// The task result returns the edited contact with the ID.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown when the parameter check fails.</exception>
        /// <exception cref="NotAuthorizedException">Thrown when not authorized to access this resource.</exception>
        /// <exception cref="NotFoundException">Thrown when the resource url could not be found.</exception>
        public async Task <Contact> EditAsync(Contact model, CancellationToken token = default)
        {
            if (model == null || model.ClientId <= 0)
            {
                throw new ArgumentException("contact or a value of the contact is null", nameof(model));
            }
            if (model.Id <= 0)
            {
                throw new ArgumentException("invalid contact id", nameof(model));
            }
            var wrappedModel = new ContactWrapper
            {
                Contact = model.ToApi()
            };

            try
            {
                var result = await PutAsync($"api/contacts/{model.Id}", wrappedModel, token);

                return(result.ToDomain());
            }
            catch (WebException wex)
                when(wex.Status == WebExceptionStatus.ProtocolError && (wex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new ArgumentException("wrong contact parameter", nameof(model), wex);
                }
        }
Example #4
0
        public static bool AjouterContactAPI(ContactEntity.User user, System.Collections.Specialized.IOrderedDictionary newValues)
        {
            ContactEntity.Contact c = new ContactEntity.Contact();

            Template template = GestionContacts.GetTemplate(ApiContact.GetStringJSonTemplate(user));

            c.setIdcontact(0);
            c.setIduser(template.getIduser());
            c.setDtcreation(DateTime.Now);
            c.setFavoris(false);
            c.setActif(true);

            if (c != null)
            {
                List <ContactEntity.Donnee> donnees = SetListeDonnees(newValues);

                c.setIduser(user.getIduser());
                c.setDtcreation(DateTime.Now);
                c.setFavoris(false);
                c.setActif(true);
                c.setDonnees(donnees);

                c.setIduser(user.getIduser());
                ContactWrapper cw = new ContactWrapper();
                cw.setContact(c);
                cw.setIdtemplate(template.getIdtemplate());
                ApiContact.SetContact(cw);
                return(true);
            }

            return(false);
        }
        private static ContactWrapper GetContactWithFotos(ContactWrapper contact)
        {
            contact.SmallFotoUrl  = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany);
            contact.MediumFotoUrl = ContactPhotoManager.GetMediumSizePhoto(contact.ID, contact.IsCompany);

            return(contact);
        }
Example #6
0
        public ContactViewModel()
        {
            event_aggregator = Unity.Container.Resolve <IEventAggregator>();
            service_factory  = Unity.Container.Resolve <IServiceFactory>();

            CurrentContact = new ContactWrapper(new Contact());
            BindCommands();
        }
Example #7
0
        public ContactViewModel()
        {
            event_aggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
            service_factory  = ServiceLocator.Current.GetInstance <IServiceFactory>();

            CurrentContact = new ContactWrapper(new Contact());
            BindCommands();
        }
Example #8
0
        public long Create(Contract.Model.Contact contact)
        {
            var mappedContact  = _contactMapper.MapToApi(contact, null);
            var wrappedContact = new ContactWrapper(mappedContact);
            var result         = _connector.Create(wrappedContact);

            return(result.id.Value);
        }
Example #9
0
        public Contract.Model.Contact Update(long id, Contract.Model.Contact contact)
        {
            var current        = _connector.GetById(id);
            var mappedContact  = _contactMapper.MapToApi(contact, current);
            var wrappedContact = new ContactWrapper(mappedContact);
            var result         = _connector.Update(id, wrappedContact);

            return(_contactMapper.MapToContract(result));
        }
        public Task <ContactWrapper <ContactAddResponse> > Contacts_Add(ClientData Client)
        {
            var Data = new ContactWrapper {
                Contact = Client,
            };

            var ret = Contacts_Add(Data);

            return(ret);
        }
Example #11
0
 public void ShouldThrowArgumentNullExceptionIfModeIsNull()
 {
     try
     {
         var wrapper = new ContactWrapper(null);
     }
     catch (ArgumentNullException exception)
     {
         Assert.AreEqual("model", exception.ParamName);
         throw;
     }
 }
Example #12
0
        public static void SaveContactAPI(ContactEntity.User user, System.Collections.Specialized.IOrderedDictionary oldValues, System.Collections.Specialized.IOrderedDictionary newValues)
        {
            if (user == null)
            {
                return;
            }

            //charge la liste des contacts par l'API
            string strJson = ContactClasse.ApiContact.GetStringJSonContacts(user);
            List <ContactEntity.Contact> ListeContacts = ContactClasse.GestionContacts.GetContacts(strJson);
            List <EvalEntity.Champ>      listeChamp    = dao.DaoChamp.GetChamps();

            int idcontact = 0;

            if (oldValues != null)
            {
                idcontact = Int32.Parse(oldValues["idcontact"] as string);
            }

            Template template = GestionContacts.GetTemplate(ApiContact.GetStringJSonTemplate(user));

            if (template != null && ListeContacts != null)
            {
                ContactEntity.Contact c = ListeContacts.Where(x => x.getIdcontact() == idcontact).FirstOrDefault();

                if (c != null)
                {
                    List <ContactEntity.Donnee> donnees = SetListeDonnees(newValues);

                    c.setIduser(user.getIduser());
                    c.setDtcreation(DateTime.Now);
                    c.setFavoris(false);
                    c.setActif(true);
                    c.setDonnees(donnees);

                    c.setIduser(user.getIduser());
                    ContactWrapper cw = new ContactWrapper();
                    cw.setContact(c);
                    cw.setIdtemplate(template.getIdtemplate());
                    ApiContact.SetContact(cw);
                }
            }
        }
Example #13
0
        private void BtnAjouter_Click(object sender, EventArgs e)
        {
            if (FormIsValid())
            {
                contact = NouveauContact();
                contact.setIduser(iduser);
                ContactWrapper cw = new ContactWrapper();
                cw.setContact(contact);
                cw.setIdtemplate(template.getIdtemplate());
                ApiContact.SetContact(cw);
                ChargerListeContact.DynamicInvoke();

                if (this.panel1.Controls["BtnAjouter"] != null && this.panel1.Controls["BtnAjouter"].Text == "Ajouter")
                {
                    contact = null;
                    this.panel1.Controls.Clear();
                    this.InitialiseChamp();
                }
            }
        }
Example #14
0
        public IActionResult JobContact(int UserId)
        {
            int?theUserId = HttpContext.Session.GetInt32("UserId");

            ViewBag.Id = theUserId;

            if (theUserId == null)
            {
                return(Logout());
            }

            ContactWrapper ContactWMod = new ContactWrapper();

            ContactWMod.TheUser = dbContext.Users
                                  .Include(user => user.Contacts)
                                  .FirstOrDefault(u => u.UserId == theUserId);

            ContactWMod.ContactList = dbContext.Contacts
                                      .Where(jsu => jsu.UserId == theUserId)
                                      .ToList();

            return(View("JobContact", ContactWMod));
        }
 internal static Contact ToDomain(this ContactWrapper value)
 {
     return(s_contactMapper.ApiToDomain(value));
 }
Example #16
0
        public void ShouldContainModelInModelProperty()
        {
            var wrapper = new ContactWrapper(_contact);

            Assert.AreEqual(_contact, wrapper.Model);
        }
Example #17
0
 public Contact ApiToDomain(ContactWrapper value)
 {
     return(ApiToDomain(value?.Contact));
 }
 internal static Contact ToDomain(this ContactWrapper value)
 {
     return(value?.Contact.ToDomain());
 }
Example #19
0
        public void ShouldGetValueOfUnderlyingModelProperty()
        {
            var wrapper = new ContactWrapper(_contact);

            Assert.AreEqual(_contact.FirstName, wrapper.FirstName);
        }
Example #20
0
        public static string SetContact(ContactWrapper cw)
        {
            string url = @"http://localhost:8080/api-set-contact";

            return(PostHttpReponse(url, cw));
        }