示例#1
0
        public async Task AddService(ServiceDTO service, string operatorId)
        {
            if (!string.IsNullOrEmpty(service?.Station?.StreetAddress))
            {
                var lonLat = await _amapProxy.Geo(service.Station.StreetAddress);

                service.Station.Longitude = lonLat?.Longitude ?? 0;
                service.Station.Latitude  = lonLat?.Latitude ?? 0;
            }

            var obj = ServiceFactory.CreateInstance(
                service.Title,
                service.Introduction,
                service.SincerityGold,
                service.ServeScope,
                service.Category,
                service.SubCategory,
                service.Station,
                service.OrganizationId,
                operatorId,
                service.ApplicationId);

            _serviceRepository.Add(obj);
            if (service.Images != null && service.Images.Count() > 0)
            {
                foreach (var img in service.Images)
                {
                    _serviceImageRepository.Add(new ServiceImage
                    {
                        CreatedOn = DateTime.Now,
                        ImageId   = img.ImageId,
                        ServiceId = obj.Id
                    });
                }
            }
            _dbUnitOfWork.Commit();
        }
示例#2
0
        public async Task AddService(ServiceDTO service, string operatorId)
        {
            if (string.IsNullOrWhiteSpace(service.IOSVideoUrl) && string.IsNullOrWhiteSpace(service.VideoUrl))
            {
                throw new ArgumentInvalidException("IOSVideoUrl和VideoUrl不能都为空!");
            }

            if (!string.IsNullOrEmpty(service?.Station?.StreetAddress))
            {
                var lonLat = await _amapProxy.Geo(service.Station.StreetAddress);

                service.Station.Longitude = lonLat?.Longitude ?? 0;
                service.Station.Latitude  = lonLat?.Latitude ?? 0;
            }

            var user = await _userServiceProxy.GetCookAppUser(operatorId);

            var orgId = "";

            if (user != null)
            {
                var servicer = _servicerRepository.GetFiltered(o => o.UserName == user.UserName).FirstOrDefault();
                if (servicer != null)
                {
                    orgId = servicer.OrganizationId;
                }
            }

            if (!string.IsNullOrEmpty(orgId))
            {
                var c = _serviceRepository.GetFiltered(o => o.OrganizationId == orgId && o.Title == service.Title).Count();
                if (c > 0)
                {
                    throw new ArgumentInvalidException("您所在的商户下已经存在您所发布的标题,请更改标题!");
                }
            }


            var obj = ServiceFactory.CreateInstance(
                service.Title,
                service.Introduction,
                service.SincerityGold,
                service.ServeScope,
                service.Category,
                service.SubCategory,
                service.Station,
                string.IsNullOrEmpty(orgId) ? service.OrganizationId : orgId,
                operatorId,
                service.VideoUrl,
                service.IOSVideoUrl,
                service.GoodsCategoryName,
                service.ApplicationId);

            _serviceRepository.Add(obj);
            if (service.Images != null && service.Images.Count() > 0)
            {
                foreach (var img in service.Images)
                {
                    _serviceImageRepository.Add(new ServiceImage
                    {
                        CreatedOn = DateTime.Now,
                        ImageId   = img.ImageId,
                        ServiceId = obj.Id
                    });
                }
            }
            _dbUnitOfWork.Commit();
        }