Beispiel #1
0
        /// <summary>
        /// 承运商信息模糊查询
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public JsonResult GetCarrierByName(string name = "", bool contactBlackCarrier = true)
        {
            List <CarrierEntity> outList = new List <CarrierEntity>();
            List <CarrierEntity> list    = CarrierService.GetCarrierAll(contactBlackCarrier);

            if (list != null && list.Count > 0)
            {
                if (!string.IsNullOrEmpty(name))
                {
                    var v = from d in list where d.CarrierName.Contains(name) select d;

                    if (v != null)
                    {
                        foreach (var k in v)
                        {
                            CarrierEntity model = new CarrierEntity();
                            model.CarrierID   = k.CarrierID;
                            model.CarrierName = k.CarrierName;
                            outList.Add(model);
                        }
                    }
                }
                else
                {
                    foreach (CarrierEntity entity in list)
                    {
                        outList.Add(entity);
                    }
                }
            }

            return(Json(outList));
        }
Beispiel #2
0
        public async Task <Carrier> AddAsync(AddCarrierRequest carrier)
        {
            try
            {
                if (carrier == null)
                {
                    throw new ArgumentNullException();
                }

                CarrierEntity entity = _mapper.Map <CarrierEntity>(carrier);

                var addResponse = await _context.Carriers.AddAsync(entity).ConfigureAwait(false);

                if (addResponse.State.Equals(EntityState.Added))
                {
                    bool created = await _context.SaveChangesAsync().ConfigureAwait(false) > 0;

                    return(created ? _mapper.Map <Carrier>(addResponse.Entity) : null);
                }
            }
            catch (Exception e)
            {
                _context.DetachAll();
                _logger.LogError(e, "Exception: {e} // Internal Error while adding new Carrier: {carrier}", e.Message, JsonSerializer.Serialize(carrier));
            }

            return(null);
        }
Beispiel #3
0
        public bool ValidateUpdate(CarrierEntity CarrierEntity)
        {
            IsValid = true;
            Carrier Carrier = UnitOfWork.CarrierRepository.Get(CarrierEntity.Id);

            if (Carrier == null)
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Id), "Item doesn't exsited.");
            }
            if (string.IsNullOrEmpty(CarrierEntity.Code))
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Code), "Must fill data.");
            }
            if (string.IsNullOrEmpty(CarrierEntity.Name))
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Name), "Must fill data.");
            }
            if (string.IsNullOrEmpty(CarrierEntity.Address))
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Address), "Must fill data.");
            }
            if (string.IsNullOrEmpty(CarrierEntity.Phone))
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Phone), "Must fill data.");
            }
            if (CarrierEntity.Errors.Count > 0)
            {
                IsValid = false;
            }
            return(IsValid);
        }
Beispiel #4
0
        public async Task <Carrier> GetByIdAsync(int carrierId)
        {
            try
            {
                if (carrierId < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }

                CarrierEntity entity = await _context.Carriers
                                       .AsNoTracking()
                                       .Include(x => x.Country)
                                       .Include(x => x.Vehicles)
                                       .Include(x => x.Drivers)
                                       .FirstOrDefaultAsync(x => x.CarrierId.Equals(carrierId))
                                       .ConfigureAwait(false);

                return(_mapper.Map <Carrier>(entity));
            }
            catch (Exception e)
            {
                _context.DetachAll();
                _logger.LogError(e, "Exception: {e} // Internal Error while retrieving Carrier: {carrierId}", e.Message, carrierId);
            }

            return(null);
        }
Beispiel #5
0
 public bool ValidateCreate(CarrierEntity CarrierEntity)
 {
     IsValid = true;
     if (string.IsNullOrEmpty(CarrierEntity.Code))
     {
         CarrierEntity.AddError(nameof(CarrierEntity.Code), "Must fill data.");
     }
     if (string.IsNullOrEmpty(CarrierEntity.Name))
     {
         CarrierEntity.AddError(nameof(CarrierEntity.Name), "Must fill data.");
     }
     if (string.IsNullOrEmpty(CarrierEntity.Address))
     {
         CarrierEntity.AddError(nameof(CarrierEntity.Address), "Must fill data.");
     }
     if (string.IsNullOrEmpty(CarrierEntity.Phone))
     {
         CarrierEntity.AddError(nameof(CarrierEntity.Phone), "Must fill data.");
     }
     if (CarrierEntity.Errors.Count > 0)
     {
         IsValid = false;
     }
     return(IsValid);
 }
Beispiel #6
0
        public async Task <bool> DeleteAsync(int carrierId)
        {
            try
            {
                CarrierEntity carrier = await _context.Carriers.FindAsync(carrierId).ConfigureAwait(false);

                if (carrier != null)
                {
                    var removedEntity = _context.Carriers.Remove(carrier);
                    if (removedEntity?.Entity != null && removedEntity.State.Equals(EntityState.Deleted))
                    {
                        int deleted = await _context.SaveChangesAsync().ConfigureAwait(false);

                        return(deleted > 0);
                    }
                }
            }
            catch (Exception e)
            {
                _context.DetachAll();
                _logger.LogError(e, "Exception: {e} // Internal Error while removing Carrier: {carrierId}", e.Message, carrierId);
            }

            return(false);
        }
        public ActionResult Edit()
        {
            string SnNum       = WebUtil.GetFormValue <string>("SnNum");
            string CarrierName = WebUtil.GetFormValue <string>("CarrierName");
            string CarrierNum  = WebUtil.GetFormValue <string>("CarrierNum");
            string Remark      = WebUtil.GetFormValue <string>("Remark");
            string CompanyID   = WebUtil.GetFormValue <string>("CompanyID");

            CarrierEntity entity = new CarrierEntity();

            entity.SnNum       = SnNum;
            entity.CarrierName = CarrierName;
            entity.CarrierNum  = CarrierNum;
            entity.Remark      = Remark;
            entity.CompanyID   = CompanyID;


            CarrierProvider provider = new CarrierProvider(CompanyID);

            int        line       = provider.Edit(entity);
            DataResult dataResult = new DataResult();

            if (line > 0)
            {
                dataResult.Code    = (int)EResponseCode.Success;
                dataResult.Message = "编辑成功";
            }
            else
            {
                dataResult.Code    = (int)EResponseCode.Exception;
                dataResult.Message = "编辑失败";
            }
            return(Content(JsonHelper.SerializeObject(dataResult)));
        }
Beispiel #8
0
        private static CarrierEntity TranslateCarrierEntity(CarrierInfo info, bool isNeedContact = false)
        {
            CarrierEntity entity = new CarrierEntity();

            if (info != null)
            {
                entity.OperatorID       = info.OperatorID;
                entity.CarrierName      = info.CarrierName;
                entity.CarrierShortName = info.CarrierShortName;
                entity.CarrierNo        = info.CarrierNo;
                entity.Type             = info.Type;
                entity.Remark           = info.Remark;
                entity.CarNo            = info.CarNo;
                entity.Status           = info.Status;
                entity.CreateDate       = info.CreateDate;
                entity.ChangeDate       = info.ChangeDate;
                entity.CarrierID        = info.CarrierID;
                if (isNeedContact)
                {
                    entity.listContact = ContactService.GetContactByRule(UnionType.Carrier.ToString(), info.CarrierID);
                    entity.ContactJson = entity.listContact != null && entity.listContact.Count > 0 ? JsonHelper.ToJson(entity.listContact) : "";
                }
            }

            return(entity);
        }
Beispiel #9
0
        public async Task <bool> UpdateAsync(Carrier carrier)
        {
            try
            {
                if (carrier == null)
                {
                    throw new ArgumentNullException();
                }

                CarrierEntity entity = await _context.Carriers
                                       .Include(x => x.Vehicles)
                                       .Include(x => x.Drivers)
                                       .FirstOrDefaultAsync(x => x.CarrierId.Equals(carrier.CarrierId))
                                       .ConfigureAwait(false);

                if (entity != null)
                {
                    _mapper.Map(carrier, entity);
                    await _context.SaveChangesAsync().ConfigureAwait(false);

                    return(true);
                }
            }
            catch (Exception e)
            {
                _context.DetachAll();
                _logger.LogError(e, "Exception: {e} // Internal Error while updating Carrier: {carrier}", e.Message, JsonSerializer.Serialize(carrier));
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="contactBlackCarrier">是否包含黑名单 </param>
        /// <returns></returns>
        public static List <CarrierEntity> GetCarrierAll(bool contactBlackCarrier = true)
        {
            List <CarrierEntity> all    = new List <CarrierEntity>();
            CarrierRepository    mr     = new CarrierRepository();
            List <CarrierInfo>   miList = Cache.Get <List <CarrierInfo> >("CarrierALL");
            //供应商黑名单
            List <BlackListEntity> blackList = BlackListService.GetBlackListAll();

            if (miList.IsEmpty())
            {
                miList = mr.GetAllCarrier();
                Cache.Add("CarrierALL", miList);
            }
            if (!miList.IsEmpty())
            {
                foreach (CarrierInfo mInfo in miList)
                {
                    if (!contactBlackCarrier && blackList != null && blackList.Count > 0 && blackList.Find(p => p.BlackType.Equals("Carrier") && p.UnionID == mInfo.CarrierID) != null)
                    {
                    }
                    else
                    {
                        CarrierEntity CarrierEntity = TranslateCarrierEntity(mInfo, true);
                        all.Add(CarrierEntity);
                    }
                }
            }

            return(all);
        }
Beispiel #11
0
        /// <summary>
        /// 查询分页
        /// </summary>
        /// <returns></returns>
        public ActionResult GetList()
        {
            string CompanyID   = WebUtil.GetFormValue <string>("CompanyID");
            int    PageIndex   = WebUtil.GetFormValue <int>("PageIndex", 1);
            int    PageSize    = WebUtil.GetFormValue <int>("PageSize", 10);
            string CarrierNum  = WebUtil.GetFormValue <string>("CarrierNum");
            string CarrierName = WebUtil.GetFormValue <string>("CarrierName");

            CarrierEntity entity = new CarrierEntity();

            entity.CompanyID   = CompanyID;
            entity.CarrierNum  = CarrierNum;
            entity.CarrierName = CarrierName;

            CarrierProvider provider = new CarrierProvider(CompanyID);
            PageInfo        pageInfo = new PageInfo()
            {
                PageIndex = PageIndex, PageSize = PageSize
            };
            List <CarrierEntity>           listResult = provider.GetList(entity, ref pageInfo);
            DataListResult <CarrierEntity> dataResult = new DataListResult <CarrierEntity>();

            dataResult.Code     = (int)EResponseCode.Success;
            dataResult.Result   = listResult;
            dataResult.PageInfo = pageInfo;
            dataResult.Message  = "响应成功";

            return(Content(JsonHelper.SerializeObject(dataResult)));
        }
Beispiel #12
0
        public static CarrierEntity GetCarrierById(long gid)
        {
            CarrierEntity     result = new CarrierEntity();
            CarrierRepository mr     = new CarrierRepository();
            CarrierInfo       info   = mr.GetCarrierByKey(gid);

            result = TranslateCarrierEntity(info);
            return(result);
        }
Beispiel #13
0
 public void Modify(CarrierEntity Carrier)
 {
     if (Carrier != null)
     {
         Carrier.OperatorID = CurrentUser.UserID;
     }
     CarrierService.ModifyCarrier(Carrier);
     Response.Redirect("/Carrier/");
 }
Beispiel #14
0
        public async Task <TData <string> > SaveForm(CarrierEntity entity)
        {
            TData <string> obj = new TData <string>();
            await carrierService.SaveForm(entity);

            obj.Data = entity.Id.ParseToString();
            obj.Tag  = 1;
            return(obj);
        }
Beispiel #15
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Edit(CarrierEntity entity)
        {
            entity.IncludeCarrierName(true).IncludeRemark(true);
            entity.Where(async => async.SnNum == entity.SnNum)
            .And(item => item.CompanyID == this.CompanyID)
            ;

            int line = this.Carrier.Update(entity);

            return(line);
        }
Beispiel #16
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="SnNum"></param>
        /// <returns></returns>
        public int Delete(string SnNum)
        {
            CarrierEntity entity = new CarrierEntity();

            entity.Where(async => async.SnNum == SnNum)
            .And(item => item.CompanyID == this.CompanyID)
            ;
            int line = this.Carrier.Delete(entity);

            return(line);
        }
Beispiel #17
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Add(CarrierEntity entity)
        {
            entity.SnNum      = entity.SnNum.IsEmpty() ? ConvertHelper.NewGuid() : entity.SnNum;
            entity.CarrierNum = entity.CarrierNum.IsEmpty() ? new TNumProvider(this.CompanyID).GetSwiftNum(typeof(CarrierEntity), 5):entity.CarrierNum;
            entity.CompanyID  = this.CompanyID;
            entity.IsDelete   = (int)EIsDelete.NotDelete;
            entity.CreateTime = DateTime.Now;
            entity.IncludeAll();
            int line = this.Carrier.Add(entity);

            return(line);
        }
Beispiel #18
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public CarrierEntity GetSingle(string SnNum)
        {
            CarrierEntity entity = new CarrierEntity();

            entity.IncludeAll();
            entity.Where(async => async.SnNum == SnNum)
            .And(item => item.CompanyID == this.CompanyID)
            ;

            entity = this.Carrier.GetSingle(entity);

            return(entity);
        }
Beispiel #19
0
        public bool Delete(EmployeeEntity EmployeeEntity, Guid CarrierId)
        {
            CarrierEntity CarrierEntity = new CarrierEntity {
                Id = CarrierId
            };

            if (!CarrierValidator.ValidateUpdate(CarrierEntity))
            {
                throw new BadRequestException(CarrierEntity);
            }
            UnitOfWork.CarrierRepository.Delete(CarrierId);
            return(true);
        }
Beispiel #20
0
        public static List <CarrierEntity> GetCarrierInfoPager(PagerInfo pager)
        {
            List <CarrierEntity> all    = new List <CarrierEntity>();
            CarrierRepository    mr     = new CarrierRepository();
            List <CarrierInfo>   miList = mr.GetAllCarrierInfoPager(pager);

            foreach (CarrierInfo mInfo in miList)
            {
                CarrierEntity carEntity = TranslateCarrierEntity(mInfo);
                all.Add(carEntity);
            }
            return(all);
        }
Beispiel #21
0
        public static CarrierEntity GetCarrierEntityById(long cid)
        {
            CarrierEntity     result = new CarrierEntity();
            CarrierRepository mr     = new CarrierRepository();
            CarrierInfo       info   = mr.GetCarrierByKey(cid);

            if (info != null)
            {
                result = TranslateCarrierEntity(info);
                //获取联系人信息
                result.listContact = ContactService.GetContactByRule(UnionType.Carrier.ToString(), info.CarrierID);
            }
            return(result);
        }
Beispiel #22
0
        public CarrierEntity Create(EmployeeEntity EmployeeEntity, CarrierEntity CarrierEntity)
        {
            if (CarrierEntity == null)
            {
                throw new NotFoundException();
            }
            if (!CarrierValidator.ValidateCreate(CarrierEntity))
            {
                throw new BadRequestException(CarrierEntity);
            }
            Carrier Carrier = new Carrier(CarrierEntity);

            UnitOfWork.CarrierRepository.Add(Carrier);
            return(Get(EmployeeEntity, Carrier.Id));
        }
Beispiel #23
0
        public bool ValidateDelete(CarrierEntity CarrierEntity)
        {
            IsValid = true;
            Carrier Carrier = UnitOfWork.CarrierRepository.Get(CarrierEntity.Id);

            if (Carrier == null)
            {
                CarrierEntity.AddError(nameof(CarrierEntity.Id), "Item doesn't exsited.");
            }
            if (CarrierEntity.Errors.Count > 0)
            {
                IsValid = false;
            }
            return(IsValid);
        }
Beispiel #24
0
        public async Task SaveForm(CarrierEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert(entity);
            }
            else
            {
                await entity.Modify();

                await this.BaseRepository().Update(entity);
            }
        }
Beispiel #25
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ActionResult GetSingle()
        {
            string SnNum     = WebUtil.GetFormValue <string>("SnNum");
            string CompanyID = WebUtil.GetFormValue <string>("CompanyID");

            CarrierProvider provider = new CarrierProvider(CompanyID);
            CarrierEntity   entity   = provider.GetSingle(SnNum);

            DataResult <CarrierEntity> dataResult = new DataResult <CarrierEntity>();

            dataResult.Code    = (int)EResponseCode.Success;
            dataResult.Result  = entity;
            dataResult.Message = "响应成功";

            return(Content(JsonHelper.SerializeObject(dataResult)));
        }
Beispiel #26
0
        public async Task <JsonResult> InsertCarrier([FromBody] CarrierEntity carrier)
        {
            try
            {
                await carrierServices.InsertCarrier(carrier);

                var result = 0;
                return(Json(result));
            }
            catch (Exception ex)
            {
                await errorServices.ErrorNotification(ex, HttpContext.User.Identity.Name, "", "");

                return(Json(ex));
            }
        }
Beispiel #27
0
        public static List <CarrierEntity> GetCarrierByKeys(string ids)
        {
            List <CarrierEntity> all    = new List <CarrierEntity>();
            CarrierRepository    mr     = new CarrierRepository();
            List <CarrierInfo>   miList = mr.GetCarrierByKeys(ids);

            if (!miList.IsEmpty())
            {
                foreach (CarrierInfo mInfo in miList)
                {
                    CarrierEntity entity = TranslateCarrierEntity(mInfo);
                    all.Add(entity);
                }
            }

            return(all);
        }
Beispiel #28
0
        public static List <CarrierEntity> GetCarrierInfoByRule(string name, string mcode, int status, PagerInfo pager)
        {
            List <CarrierEntity> all    = new List <CarrierEntity>();
            CarrierRepository    mr     = new CarrierRepository();
            List <CarrierInfo>   miList = mr.GetCarrierInfoByRule(name, mcode, status, pager);

            if (!miList.IsEmpty())
            {
                foreach (CarrierInfo mInfo in miList)
                {
                    CarrierEntity storeEntity = TranslateCarrierEntity(mInfo);
                    all.Add(storeEntity);
                }
            }

            return(all);
        }
Beispiel #29
0
        public async Task <JsonResult> UpdateCarrier([FromBody] CarrierEntity carrier, int headerId)
        {
            try
            {
                string userUniqueName = HttpContext.User.Identity.Name;
                await carrierServices.UpdateCarrier(carrier, headerId, userUniqueName);

                var result = 0;
                return(Json(result));
            }
            catch (Exception ex)
            {
                await errorServices.ErrorNotification(ex, HttpContext.User.Identity.Name, "", "");

                return(Json(ex));
            }
        }
Beispiel #30
0
        private static ReceiverEntity TranslateReceiverEntity(ReceiverInfo info, bool isRead = true)
        {
            ReceiverEntity entity = new ReceiverEntity();

            if (info != null)
            {
                entity.CustomerID       = info.CustomerID;
                entity.ReceiverType     = info.ReceiverType;
                entity.DefaultCarrierID = info.DefaultCarrierID;
                entity.DefaultStorageID = info.DefaultStorageID;
                entity.ProvinceID       = info.ProvinceID;
                entity.CityID           = info.CityID;
                entity.Address          = info.Address;
                entity.Remark           = info.Remark;

                entity.OperatorID   = info.OperatorID;
                entity.ReceiverName = info.ReceiverName;
                entity.ReceiverNo   = info.ReceiverNo;
                entity.Status       = info.Status;
                entity.CreateDate   = info.CreateDate;
                entity.ChangeDate   = info.ChangeDate;
                entity.ReceiverID   = info.ReceiverID;

                if (isRead)
                {
                    City     city     = BaseDataService.GetAllCity().FirstOrDefault(t => t.CityID == info.CityID) ?? new City();
                    Province province = BaseDataService.GetAllProvince().FirstOrDefault(t => t.ProvinceID == info.ProvinceID) ?? new Province();
                    entity.province = province;
                    entity.city     = city;
                    entity.customer = new CustomerEntity();
                    entity.customer = CustomerService.GetCustomerById(info.CustomerID);

                    CarrierEntity carrier = CarrierService.GetCarrierById(info.DefaultCarrierID);
                    entity.Carrier = carrier;

                    StorageEntity storage = StorageService.GetStorageEntityById(info.DefaultStorageID);
                    entity.Storage = storage;
                }
                //获取联系人信息
                entity.listContact = ContactService.GetContactByRule(UnionType.Receiver.ToString(), info.ReceiverID);
            }

            return(entity);
        }