public IVRProfile Create(IVRProfile item)
        {
            var entity = IVRProfileToEntityMapper.ConvertToEntity(item);

              TableOperation insertOperation = TableOperation.Insert(entity);
              var result = profilesTable.Execute(insertOperation);

              IVRProfileEntity entityResult = (IVRProfileEntity)result.Result;

              return IVRProfileToEntityMapper.ConvertFromEntity(entityResult);
        }
        internal static IVRProfile ConvertFromEntity(IVRProfileEntity entity)
        {
            IVRProfile ret = new IVRProfile()
              {
            FullName = entity.FullName,
            Culture = entity.Culture,
            ProfileId = entity.ProfileId,
            PhoneNumber = entity.PhoneNumber,
            PIN = entity.PIN
              };

              return ret;
        }
            public void ShouldCreateAProfile()
            {
                IVRProfile profileToCreate = new IVRProfile()
                {
                  ProfileId = 1000001,
                  FullName = "basil",
                  PIN = "1234"
                };

                ProfileRepository repository = new ProfileRepository(DEVELOPMENT_CONNECTION_STRING);

                var result = repository.Create(profileToCreate);

                Assert.IsNotNull(result);
            }
        internal static IVRProfileEntity ConvertToEntity(IVRProfile profile)
        {
            IVRProfileEntity ret = new IVRProfileEntity()
              {
            FullName = profile.FullName,
            Culture = profile.Culture,
            ProfileId = profile.ProfileId,
            PhoneNumber = profile.PhoneNumber,
            PIN = profile.PIN,
            RowKey = profile.ProfileId.ToString(),
            PartitionKey = (profile.ProfileId).ToString().Substring(0, 2)
              };

              return ret;
        }
        public bool Delete(IVRProfile item)
        {
            //Azure storage will throw a StorageException --- 404 --- if it cannot find the entity to delete.

              var entity = IVRProfileToEntityMapper.ConvertToEntity(item);

              entity.ETag = "*";

              TableOperation deleteOperation = TableOperation.Delete(entity);

              try
              {
            var result = profilesTable.Execute(deleteOperation);

            return true;
              }
              catch (StorageException)
              {
            return false;
              }
        }
        public bool Update(IVRProfile profile)
        {
            var profileEntity = IVRProfileToEntityMapper.ConvertToEntity(profile);

              TableOperation retrievalOperation = TableOperation.Retrieve<IVRProfileEntity>(profileEntity.PartitionKey, profileEntity.RowKey);

              var retrievalResult = profilesTable.Execute(retrievalOperation);

              var entityToUpdate = (IVRProfileEntity)retrievalResult.Result;

              if (entityToUpdate != null)
              {
            IVRProfileToEntityMapper.UpdateEntity(entityToUpdate, profileEntity);

            TableOperation updateOperation = TableOperation.Replace(entityToUpdate);
            var updateResult = profilesTable.Execute(updateOperation);

            return true;
              }

              return false;
        }
            public void ShouldUpdateProfile()
            {
                IVRProfile profile = new IVRProfile()
                {
                  ProfileId = 11112,
                  Culture = "en",
                  PIN = "1234",
                  FullName = "Basil",
                  PhoneNumber = "+22222221"
                };

                ProfileRepository repository = new ProfileRepository(DEVELOPMENT_CONNECTION_STRING);

                var createdEntity = repository.Create(profile);

                createdEntity.Culture = "fr";
                createdEntity.PhoneNumber = "+1111112";
                createdEntity.PIN = "4321";

                repository.Update(createdEntity);

                var updatedEntity = repository.Get(11112);

                Assert.AreEqual(createdEntity.Culture, updatedEntity.Culture);
                Assert.AreEqual(createdEntity.PhoneNumber, updatedEntity.PhoneNumber);
                Assert.AreEqual(createdEntity.PIN, updatedEntity.PIN);
            }
        public ActionResult SetupPINAccess(FormCollection form)
        {
            int profileId = int.Parse(form["profileId"]);
              string pin = form["PIN"];
              string language = form["Language"];
              string phoneNumber = string.Format("{0}{1}", form["DialCode"], form["CellPhoneNumber"]);
              string fullName = (string.IsNullOrEmpty(form["FullName"])) ? "" : form["FullName"];

              Response.Cookies.Add(new HttpCookie("RefProfileId", profileId.ToString()));

              var ivrProfile = new IVRProfile()
              {
            ProfileId = profileId,
            PIN = pin,
            Culture = language,
            PhoneNumber = phoneNumber,
            FullName = fullName
              };

              bool exists = profileManager.CheckIfProfileExists(profileId);

              if (exists)
              {
            profileManager.UpdateProfile(ivrProfile);
              }
              else
              {
            profileManager.CreateProfile(ivrProfile);
              }

              return RedirectToAction("SetupComplete");
        }
 public void CreateProfile(IVRProfile profile)
 {
     profileRepository.Create(profile);
 }
 public void UpdateProfile(IVRProfile profile)
 {
     profileRepository.Update(profile);
 }