Esempio n. 1
0
        public IActionResult GetById(int id, int cid)
        {
            var item = _addressRepository.Find(cid, id);

            if (item == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(item));
        }
        public async Task <IActionResult> GetAddress(int id)
        {
            try
            {
                var address = await _repo.Find <Database.Entities.Address>(id);

                return(Ok(address));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                return(StatusCode((int)HttpStatusCode.InternalServerError, "Error!"));
            }
        }
        protected override async System.Threading.Tasks.Task OnReceived(IRequest request, string connectionId, string data)
        {
            var t = _demoService.Add(2);
            var s = _addressRepository.Find(1, 1);

            await Connection.Send(connectionId, data);
        }
        public AddressModel Find(int addressId, int childAgent)
        {
            var response = new AddressModel();
            var address  = _AddressRepository.Find(addressId, childAgent);

            if (address == null)
            {
                return(null);
            }
            //解析address对象
            response = Helper.CopySameFieldsObject <AddressModel>(address);
            //城市名称
            var areas = _areaService.Find();
            //省
            var province = areas.FirstOrDefault(x => x.Id == response.provinceId);

            if (province != null)
            {
                response.provinceName = province.Name;
                //市
                var city = _areaService.FindByPid(province.Id).FirstOrDefault(x => x.Id == response.cityId);
                if (city != null)
                {
                    response.cityName = city.Name;
                    //区
                    var area = _areaService.FindByPid(city.Id).FirstOrDefault(x => x.Id == response.areaId);
                    if (area != null)
                    {
                        response.areaName = area.Name;
                    }
                }
            }
            return(response);
        }
Esempio n. 5
0
        public Task <IViewComponentResult> InvokeAsync(int orderId)
        {
            var         order = _orderRepository.Find(orderId);
            CultureInfo cul   = CultureInfo.GetCultureInfo("vi-VN");

            var userAddress    = _addressRepository.Find(order.AddressId);
            var deliveryInfoVM = new OrderDeliveryInfoViewModel
            {
                RecipientFullName = order.Address.RecipientName,
                PhoneNumber       = order.Address.PhoneNumber,
                Email             = order.Address.Customer.Email,
                ReceivingTypeName = order.ReceivingType.Name,
                PaymentType       = order.PaymentType,
                Status            = order.Status,
                DeliveryDate      = order.DeliveryDate ?? order.OrderDate,
                //ShippingFee = double.Parse(order.ShippingFee.ToString()).ToString("#,###", cul.NumberFormat)
                ShippingFee = CommonFunctions.FormatPrice(order.ShippingFee.Value.ToString())
            };
            var address = order.Address;

            if (userAddress != null && address != null)
            {
                var detail   = !string.IsNullOrEmpty(address.Detail) ? $"{address.Detail}, " : "";
                var ward     = !string.IsNullOrEmpty(address.Ward) ? $"{address.Ward}, " : "";
                var district = !string.IsNullOrEmpty(address.District) ? $"{address.District}, " : "";
                var province = !string.IsNullOrEmpty(address.Province) ? $"{address.Province}" : "";
                deliveryInfoVM.Address = $"{detail}{ward}{district}{province}";
            }
            else
            {
                deliveryInfoVM.Address = string.Empty;
            }
            return(Task.FromResult <IViewComponentResult>(View(deliveryInfoVM)));
        }
Esempio n. 6
0
        public IActionResult GetById(string id)
        {
            passport = CommonMethod.GetPassport(Request);
            var item = service.Find(passport, id);

            if (item == null)
            {
                return(NotFound());
            }
            ResultModel result = new ResultModel(true, item);

            return(new ObjectResult(result));
        }
Esempio n. 7
0
        public IActionResult OnPostSaveAddress([FromBody] UserAddressViewModel model)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            var user = _userManager.GetUserAsync(HttpContext.User).Result;

            if (model.AddressId > 0)
            {
                var existAddress = _addressRepository.Find(model.AddressId);
                existAddress.PhoneNumber   = model.PhoneNumber;
                existAddress.RecipientName = model.RecipientName;
                existAddress.Ward          = model.Ward;
                existAddress.District      = model.District;
                existAddress.Province      = model.Province;
                existAddress.Detail        = model.Detail;
                existAddress.DateModified  = DateTime.Now;
                _addressRepository.Update(existAddress);
                return(new OkObjectResult(existAddress));
            }
            var newAddress = new Address
            {
                PhoneNumber   = model.PhoneNumber,
                RecipientName = model.RecipientName,
                Ward          = model.Ward,
                District      = model.District,
                Province      = model.Province,
                Detail        = model.Detail,
                DateCreated   = DateTime.Now,
                DateModified  = DateTime.Now,
                CustomerId    = _userManager.GetUserAsync(HttpContext.User).Result.Id
            };

            _addressRepository.Add(newAddress);
            return(new OkObjectResult(newAddress));
        }
Esempio n. 8
0
 public Address GetAddressById(string id)
 {
     return(Repository.Find(id));
 }
Esempio n. 9
0
        public async Task <Result> AddedAsync(ContactAddClient contactClient)
        {
            var result = new Result();
            await Task.Run(() =>
            {
                var existed_title = _titleRepository.Exist(new Title()
                {
                    Name = contactClient.Title
                });

                var title = new Title()
                {
                    Name = contactClient.Name
                };

                Address new_address = contactClient.GetAddress();
                var existed_address = _addressRepository
                                      .Find(new AddressExistSpecification(new_address).SpecExpression())
                                      .FirstOrDefault();

                Address new_deliveryAddress     = contactClient.GetDeliveryAdress();
                Address existed_deliveryAddress = null;
                if (!contactClient.IsDeliverSameAsHomeAddress)
                {
                    existed_deliveryAddress = _addressRepository
                                              .Find(new AddressExistSpecification(new_deliveryAddress).SpecExpression())
                                              .FirstOrDefault();

                    if (existed_deliveryAddress == null)
                    {
                        _addressRepository.Add(new_deliveryAddress);
                        _addressRepository.Complete();
                    }
                }

                var contact     = contactClient.GetContact();
                contact.TitleId = existed_title == null ? title.Id : existed_title.Id;
                contact.Title   = existed_title == null ? title : null;

                contact.HomeAddress = existed_address == null ? new_address : null; /* we don't want to add existed address again (fail) */
                contact.AddressId   = existed_address == null ? new_address.Id : existed_address.Id;

                contact.DeliveryAddressId = contactClient.IsDeliverSameAsHomeAddress
                                            ? new_address.Id
                                            : (existed_deliveryAddress != null ? existed_deliveryAddress.Id : new_deliveryAddress.Id);


                var existed_contact = _contactRepository.Find(new ContactExistSpecification(contact).SpecExpression());
                if (existed_contact == null)
                {
                    _contactRepository.Add(contact);
                }
                else
                {
                    result.Message = "Client exist, no new contact is created";
                    result.IsError = true;
                }
            });

            _contactRepository.Complete();

            return(result);
        }
Esempio n. 10
0
 public IList <Address> GetByUserId(string UserId)
 {
     return(addressRepository.Find(d => d.ApplicationUserId == UserId).ToList());;
 }
Esempio n. 11
0
        //
        // GET: /Addresses/Details/5

        public ViewResult Details(int id)
        {
            return(View(addressRepository.Find(id)));
        }