예제 #1
0
        /// <summary>
        /// Load the test data from the json files
        /// </summary>
        /// <param name="context"></param>
        public static void LoadData(AgentContext context)
        {
            var agents = JsonConvert.DeserializeObject <List <Agent> >(File.ReadAllText(agentFileName));

            foreach (var agent in agents)
            {
                try
                {
                    context.Agents.Add(agent);
                    context.SaveChanges();
                }
                catch (Exception)
                { }
            }

            var customers = JsonConvert.DeserializeObject <List <Customer> >(File.ReadAllText(customersFileName));

            foreach (var customer in customers)
            {
                try
                {
                    context.Customers.Add(customer);
                    context.SaveChanges();
                }
                catch (Exception)
                { }
            }
        }
        public ActionResult <AccommodationDTO> AddAccommodation(AccommodationDTO body)
        {
            AccommodationPortClient accPortClient = new AccommodationPortClient();
            addAccommodationRequest accRequest    = new addAccommodationRequest
            {
                AccommodationDTO = body
            };

            var acc = accPortClient.addAccommodationAsync(accRequest);

            acc.Wait();

            AccommodationDTO accTemp = new AccommodationDTO();

            accTemp = acc.Result.addAccommodationResponse.AccommodationDTO;

            Accommodation accommodation = accTemp.CreateAccommodation();

            // attach type in context so it doesn't get saved in database again and check the same for location
            _context.AccommodationTypes.Attach(accommodation.AccommodationType);

            if (_context.Locations.Any(loc => loc.Id == accommodation.Location.Id))
            {
                _context.Locations.Attach(accommodation.Location);
            }

            _context.Accommodations.Add(accommodation);
            _context.SaveChanges();

            return(Ok(accTemp));
        }
예제 #3
0
        public int AddAgent(BusinessEntities businessEntityObj)
        {
            businessEntityObj.CreatedOnUtc = DateTime.Now;
            businessEntityObj.UpdatedOnUtc = DateTime.Now;

            agentContextObj.BusinessEntities.Add(businessEntityObj);

            return(agentContextObj.SaveChanges());
        }
예제 #4
0
 /// <summary>
 /// Сохранение данных в базу данных
 /// </summary>
 /// <param name="agent">Записываемый агент</param>
 /// <param name="name">Имя агента</param>
 /// <param name="contactNumber">Номер телефона агента</param>
 /// <param name="email">Email агента</param>
 /// <param name="isEdit">Флаг режима, запись нового агента или его редактирование</param>
 public void SaveDataToDataBaseAsync(Agent agent, string name, string contactNumber, string email, bool isEdit)
 {
     using (var db = new AgentContext())
     {
         if (agent == null)
         {
             agent = new Agent()
             {
                 Name          = name,
                 ContactNumber = contactNumber,
                 Email         = email
             };
         }
         else
         {
             agent.Name          = name;
             agent.ContactNumber = contactNumber;
             agent.Email         = email;
         }
         if (Token != null)
         {
             agent.ImageToken = Token;
         }
         if (isEdit)
         {
             db.Agents.Update(agent);
         }
         else
         {
             db.Agents.Add(agent);
         }
         db.SaveChanges();
     }
     Navigation.GoToMainPage();
 }
예제 #5
0
        public async Task <ActionResult> FetchAgents(string category, string city)
        {
            try {
                var agents = ConvertSourceResultsToAgents
                             (
                    await FetchResults($"/?type={category}&zo=/"),
                    ListingType.All
                             );

                _context.AddRange(agents);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(ExceptionResult(e));
            }

            return(Ok());
        }
예제 #6
0
        public bool CreateAccount(string name)
        {
            // Start cleos to unlock the wallet
            var publicKey = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json")).eos.keyPair.publicKey;
            var result    = ExecuteCleosCommand($"create account eosio {name} {publicKey} {publicKey}");

            if (!result.IsSucceeded)
            {
                Console.WriteLine("[Dasdaq Dev Agent] Create account process returned " + result.ExitCode);
                return(false);
            }

            _ef.Accounts.Add(new Account
            {
                Name = name
            });
            _ef.SaveChanges();
            return(true);
        }
예제 #7
0
        public void StopDapp(string name)
        {
            var instance = _ef.Instances.SingleOrDefault(x => x.Name == name);

            if (instance == null)
            {
                Console.WriteLine("[Dasdaq Dev Agent] Dapp is not found.");
                return;
            }


            if (_dic.ContainsKey(name))
            {
                _proc.KillProcessTree(_dic[name].Process.Id);
            }

            _ef.Remove(instance);
            _ef.SaveChanges();
        }
 public void Add(Accommodation newAccommodation)
 {
     _context.Add(newAccommodation);
     _context.SaveChanges();
 }
        public ActionResult EditMyDetails(UserDetailsViewModel vm)
        {
            if (!ModelState.IsValid || vm.CurrentUser.SecQ2Index == vm.CurrentUser.SecQ1Index || vm.CurrentUser.SecQ3Index == vm.CurrentUser.SecQ1Index || vm.CurrentUser.SecQ3Index == vm.CurrentUser.SecQ2Index)
            {
                vm.Questions = GetSelectListItems(SecurityQuestions);
                return(View(vm));
            }
            User  foundUser  = _userContext.Users.First(u => u.Id.ToString() == HttpContext.Session.GetString(UserId));
            Agent foundAgent = _agentContext.Agents.First(p => p.UserId == foundUser.Id);


            SHA512 hasher = new SHA512Managed();

            if (!string.IsNullOrEmpty(vm.CurrentUser.Password))
            {
                byte[] saltedPwd       = Encoding.ASCII.GetBytes(vm.CurrentUser.Password + Encoding.ASCII.GetString(foundUser.Salt));
                byte[] saltedHashedPwd = hasher.ComputeHash(saltedPwd);
                foundUser.PasswordHash = saltedHashedPwd;
            }

            foundUser.SecQ1Index = vm.CurrentUser.SecQ1Index;
            foundUser.SecQ2Index = vm.CurrentUser.SecQ2Index;
            foundUser.SecQ3Index = vm.CurrentUser.SecQ3Index;

            if (!string.IsNullOrEmpty(vm.CurrentUser.SecQ1Response))
            {
                byte[] saltedQ1       = Encoding.ASCII.GetBytes(vm.CurrentUser.SecQ1Response + Encoding.ASCII.GetString(foundUser.Salt));
                byte[] saltedHashedQ1 = hasher.ComputeHash(saltedQ1);
                foundUser.SecQ1ResponseHash = saltedHashedQ1;
            }
            if (!string.IsNullOrEmpty(vm.CurrentUser.SecQ2Response))
            {
                byte[] saltedQ2       = Encoding.ASCII.GetBytes(vm.CurrentUser.SecQ2Response + Encoding.ASCII.GetString(foundUser.Salt));
                byte[] saltedHashedQ2 = hasher.ComputeHash(saltedQ2);
                foundUser.SecQ2ResponseHash = saltedHashedQ2;
            }
            if (!string.IsNullOrEmpty(vm.CurrentUser.SecQ3Response))
            {
                byte[] saltedQ3       = Encoding.ASCII.GetBytes(vm.CurrentUser.SecQ3Response + Encoding.ASCII.GetString(foundUser.Salt));
                byte[] saltedHashedQ3 = hasher.ComputeHash(saltedQ3);
                foundUser.SecQ3ResponseHash = saltedHashedQ3;
            }

            if (!string.IsNullOrEmpty(vm.CurrentAgent.Name))
            {
                foundAgent.Name = vm.CurrentAgent.Name;
            }
            if (!string.IsNullOrEmpty(vm.CurrentAgent.Pronouns))
            {
                foundAgent.Pronouns = vm.CurrentAgent.Pronouns;
            }

            _userContext.Users.Update(foundUser);
            _userContext.SaveChanges();
            _agentContext.Agents.Update(foundAgent);
            _agentContext.SaveChanges();

            HttpContext.Session.SetString(Name, foundAgent.Name);
            HttpContext.Session.SetString(Username, foundUser.Username);

            return(RedirectToAction("MyDetails"));
        }