예제 #1
0
        public virtual void Update(T entity, string user = "******")
        {
            entity.AddInverseReferences(user);

            var result = Validator.Validate(entity, ValidationTypes.Update);

            if (!result.IsValid)
            {
                throw new ValidatorException(result.Errors);
            }

            using (var session = HelperRepository.OpenSession())
            {
                var repo = session.GetRepository <T>();
                try
                {
                    session.StartTransaction();

                    entity.DataAlteracao    = DateTime.Now;
                    entity.UsuarioAlteracao = user;
                    repo.Update(entity);

                    session.CommitTransaction();
                }
                catch (Exception)
                {
                    session.RollBackTransaction();
                    throw;
                }
            }
        }
예제 #2
0
        public virtual void Delete(long id)
        {
            using (var session = HelperRepository.OpenSession())
            {
                var repo = session.GetRepository <T>();
                try
                {
                    session.StartTransaction();

                    var entity = repo.Get(id);
                    var result = Validator.Validate(entity, ValidationTypes.Delete);
                    if (!result.IsValid)
                    {
                        throw new ValidatorException(result.Errors);
                    }

                    repo.Delete(entity);

                    session.CommitTransaction();
                }
                catch (Exception)
                {
                    session.RollBackTransaction();
                    throw;
                }
            }
        }
예제 #3
0
        public virtual void Insert(string user, params T[] entities)
        {
            var result = Validator.Validate(entities, ValidationTypes.Insert);

            if (!result.IsValid)
            {
                throw new ValidatorException(result.Errors);
            }

            using (var session = HelperRepository.OpenSession())
            {
                var repo = session.GetRepository <T>();
                try
                {
                    session.StartTransaction();

                    foreach (var entity in entities)
                    {
                        entity.AddInverseReferences(user);

                        entity.DataInclusao    = DateTime.Now;
                        entity.UsuarioInclusao = user;
                        repo.Insert(entity);
                    }

                    session.CommitTransaction();
                }
                catch (Exception)
                {
                    session.RollBackTransaction();
                    throw;
                }
            }
        }
예제 #4
0
        public ActionResult <string> Get()
        {
            string code = new HelperRepository( ).generateIds((int)Enums.CreationNumberCode.order, DateTime.Now);


            return(code);
        }
예제 #5
0
        public ResponseClass <AgentResponse> AddAgent(RequestClass <AgentData> request)
        {
            try
            {
                if (!_repositoryGuard.IsValidAdmin(request.Token))
                {
                    throw new Exception("Неверные данные авторизации");
                }
                request.Data.Password = HelperRepository.EncrypteText(request.Data.Account + "!#").Substring(0, 6);

                ResponseClass <AgentResponse> response = new ResponseClass <AgentResponse>();
                response.Data    = _repositoryAdmin.AddAgent(request.Data.Account, request.Data.Password, request.Data.Name, request.Data.IsTest);
                response.Code    = 0;
                response.Message = "Success";
                return(response);
            }
            catch (Exception e)
            {
                ResponseClass <AgentResponse> response = new ResponseClass <AgentResponse>();
                response.Code    = -1;
                response.Message = e.Message;

                return(response);
            }
        }
예제 #6
0
 public async Task Execute(IJobExecutionContext context)
 {
     _context = new ApiContext(Global.GetConnectionString());
     repo     = new HelperRepository(_context, _mapper);
     try
     {
         var getTicks = await repo.GetTicksForOffers();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Print(ex.ToString());
     }
 }
예제 #7
0
        public async Task <IActionResult> Index(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                AccountModel user = _repository.GetAccount(model);
                if (user.Login != null)
                {
                    if (user.Login == "Hermes")
                    {
                        var claims = new List <Claim>
                        {
                            new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login),
                            new Claim(ClaimsIdentity.DefaultRoleClaimType, "P7ktrav5PL5BgPHTxF7eTFTmbtaMWpPpvzZJmtDSDwEgACQcqdxaNLta8CcZ"),
                            new Claim(ClaimsIdentity.DefaultIssuer, model.Password)
                        };
                        ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
                        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id));

                        return(this.RedirectToAction("GetAgents", "Agent"));
                    }
                    else
                    {
                        var claims = new List <Claim>
                        {
                            new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login),
                            new Claim(ClaimsIdentity.DefaultRoleClaimType, HelperRepository.DecrypteText(user.Token)),
                            new Claim(ClaimsIdentity.DefaultIssuer, model.Password)
                        };
                        ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
                        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id));

                        return(this.RedirectToAction("Index", "Cabinet"));
                    }
                }
                ModelState.AddModelError("", "Неверный логин или пароль!");
                ViewBag.Validate = "Неверный логин или пароль!";
            }
            return(this.View());
        }
예제 #8
0
 public HelperService(HelperRepository helperRepository)
 {
     _helperRepository = helperRepository;
 }