public void Insert(CostumerModel entity)
 {
     if (entity.Email.Length > 70)
     {
         throw new DbUpdateException("Erro", new Exception());
     }
 }
Exemplo n.º 2
0
        public async Task <CostumerModel> GetByIdAsync(int id)
        {
            var costumerEntity = await _costumerRepository.GetByIdAsync(id);

            CostumerModel costumerModel = costumerEntity?.Project <CostumerEntity, CostumerModel>();

            return(costumerModel);
        }
 public void IdentifyCostumer()
 {
     Costumer = Request.Headers.ContainsKey(Strings.CostumerObject) ?
                JsonConvert.DeserializeObject <CostumerModel>(Request.Headers[Strings.CostumerObject]) :
                new CostumerModel {
         Name = "Not Authorized"
     };
 }
        public void ExcecaoQuandoInsiroClienteNulo()
        {
            var           repositoryStub = new CostumerRepositoryStub();
            var           service        = new CostumerService(repositoryStub);
            CostumerModel costumer       = null;

            var mensagemEsperada = "Cliente deve ser informado.";

            var exception = Assert.Throws <InvalidServiceRequestException>(() => service.Insert(costumer));

            Assert.Equal(mensagemEsperada, exception.Message);
        }
        public void Update(CostumerModel model)
        {
            this.ValidateModel(model);

            try
            {
                repository.Update(model);
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                //--TODO: Usar Entity validate
                throw new InvalidServiceRequestException("Algo deu errado. Verifique se informações e números de caracteres estão corretos.");
            }
        }
        public void ExcecaoQuandoInsiroClienteSemNome()
        {
            var           repositoryStub = new CostumerRepositoryStub();
            var           service        = new CostumerService(repositoryStub);
            CostumerModel costumer       = new CostumerModel {
                Email = "*****@*****.**", Endereco = "ddsf dsf dsf ds fsdfsdf sdfdsff sdfd"
            };

            var mensagemEsperada = "Nome de cliente deve ser informado";

            var exception = Assert.Throws <InvalidServiceRequestException>(() => service.Insert(costumer));

            Assert.Equal(mensagemEsperada, exception.Message);
        }
        private void ValidateModel(CostumerModel model)
        {
            if (model == null)
            {
                throw new InvalidServiceRequestException("Cliente deve ser informado.");
            }

            if (string.IsNullOrWhiteSpace(model.Nome))
            {
                throw new InvalidServiceRequestException("Nome de cliente deve ser informado");
            }

            if (string.IsNullOrWhiteSpace(model.Email))
            {
                throw new InvalidServiceRequestException("Email de cliente deve ser informado");
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            using (var stream = new StreamReader(Request.Body))
            {
                var     body    = stream.ReadToEnd();
                Message message = Client.ParseMessage(Request.Method, Request.ContentType, body);


                var client = new Yandex.Checkout.V3.Client(shopId: Strings.YandexShopId, secretKey: Strings.YandexAPIKey);

                if (message.Event == Event.RefundSucceeded)
                {
                    return(JsonHelper.JsonResponse(Strings.StatusOK, Constants.HttpOkCode));
                }

                if (message.Event == Event.PaymentSucceeded && message.Object.Amount.Value == 1.00m)
                {
                    try
                    {
                        var refund = client.CreateRefund(new NewRefund {
                            PaymentId = message.Object.Id, Amount = message.Object.Amount
                        });
                    }
                    catch { }

                    var costumer = await CostumerModel.GetCostumerByOrderId(_appRepository, message.Object.Id);

                    if (costumer == null)
                    {
                        return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Wrong OrderId"));
                    }

                    await costumer.SetCardStatus(_appRepository, CardsStatus.Ok);

                    await costumer.AddBinding(_appRepository, new CardBindingModel
                    {
                        BindingId         = message.Object.Id,
                        FirstDigits       = message.Object.PaymentMethod.Card.First6,
                        LastDigits        = message.Object.PaymentMethod.Card.Last4,
                        PaymentSystemName = message.Object.PaymentMethod.Card.CardType
                    });
                }

                return(JsonHelper.JsonResponse(Strings.StatusOK, Constants.HttpOkCode));
            }
        }
        public async Task <IActionResult> OnGetAsync(string from, string orderId)
        {
            //if (string.IsNullOrEmpty(orderId)) return JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Wrong OrderId");
            //var costumer = await CostumerModel.GetCostumerByOrderId(_appRepository, orderId);
            //if (costumer == null) return JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Wrong OrderId");

            //var uri = Strings.SberPostBindings + $"?userName={Strings.SberApiLogin}&password={Strings.SberApiPassword}&clientId={costumer.Id}";
            //var request = WebRequest.Create(uri);
            //request.Method = "POST";

            //var httpResponse = (HttpWebResponse)request.GetResponse();
            //using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            //{
            //    var resultString = streamReader.ReadToEnd();
            //    var result = JsonConvert.DeserializeObject<AcquaringResponse>(resultString);
            //    if(result.ErrorCode == "0")
            //    {
            //        if (result.Bindings != null && result.Bindings.Count() > 0)
            //        {
            //            await costumer.ClearBindings(_appRepository);
            //            foreach(var binding in result.Bindings)
            //            {
            //                await costumer.AddBinding(_appRepository, new CardBindingModel
            //                {
            //                    BindingId = binding.BindingId,
            //                    ExpiryDate = binding.ExpiryDate,
            //                    MaskedPan = binding.MaskedPan
            //                });
            //            }
            //        }
            //    }
            //}

            var costumer = await CostumerModel.GetCostumerByOrderId(_appRepository, orderId);

            if (costumer == null)
            {
                return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Wrong OrderId"));
            }

            await costumer.SetCardStatus(_appRepository, CardsStatus.Ok);

            return(Redirect(from == Strings.GoToClientPage ? "/costumer" : from == Strings.GoToTakePage ? "/take/selecttariff" : "/Index"));
        }
        public void Insert(CostumerModel model)
        {
            this.ValidateModel(model);

            model.Id          = null;
            model.DateCreated = DateTime.Now;

            if (repository.GetAll().Any(c => c.Nome.Equals(model.Nome)))
            {
                throw new InvalidServiceRequestException("Já existe um cliente com o nome informado.");
            }

            try
            {
                repository.Insert(model);
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                //--TODO: Usar Entity validate
                throw new InvalidServiceRequestException("Algo deu errado. Verifique se informações e números de caracteres estão corretos.");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Müşteri Sayfasını döner. Müşteri giriş yapmışsa müşterilerin kayıtlarını çekip döner
        /// </summary>
        /// <returns></returns>
        public IActionResult SupportIndex()
        {
            var costumerSession = HttpContext.Session.GetString("costumer");

            using (var unitofWork = new UnitOfWork(masterContext))
            {
                if (costumerSession != null)
                {
                    costumer = new CostumerModel();
                    costumer = JsonConvert.DeserializeObject <CostumerModel>(costumerSession);
                    var fileList = unitofWork.GetRepository <FileModel>().GetAll().
                                   Where(x => x.CostumerId == costumer.CostumerId).ToList();
                    return(View(fileList));
                }
                var adminSession = HttpContext.Session.GetString("admin");
                if (adminSession != null)
                {
                    var fileList = unitofWork.GetRepository <FileModel>().GetAll().ToList();
                    return(View(fileList));
                }
                return(RedirectToAction("LoginIndex", "Login"));
            }
        }
 public void Update(CostumerModel entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 public void Put([FromBody] CostumerModel value)
 {
     service.Update(value);
 }
Exemplo n.º 14
0
 public void Post([FromBody] CostumerModel value)
 {
     service.Insert(value);
 }