public SetTariffModel GetTariffById(Guid tariffId) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); var permissionRangeWrite = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write); var permissionRangeDelete = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Delete); var tariff = DataContext.Get(x => x.Id == tariffId).FirstOrDefault(); var data = mapper.Map <SetTariffModel>(tariff); BaseUpdateModel baseModel = new BaseUpdateModel { UserCreated = data.UserCreated, CompanyId = data.CompanyId, DepartmentId = data.DepartmentId, OfficeId = data.OfficeId, GroupId = data.GroupId }; data.Permission = new PermissionAllowBase { AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser), AllowDelete = PermissionExtention.GetPermissionDetail(permissionRangeDelete, baseModel, currentUser), }; data.UserCreatedName = userRepository.Get(x => x.Id == data.UserCreated).FirstOrDefault()?.Username; data.UserModifieddName = userRepository.Get(x => x.Id == data.UserModified).FirstOrDefault()?.Username; return(data); }
public IQueryable <TariffViewModel> Paging(TariffCriteria criteria, int page, int size, out int rowsCount) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { rowsCount = 0; return(null); } List <TariffViewModel> results = null; // var list = Query(criteria); IQueryable <TariffViewModel> list = QueryPermission(criteria, rangeSearch); if (list == null) { rowsCount = 0; return(null); } list = list.OrderByDescending(x => x.DatetimeModified); rowsCount = list.ToList().Count; if (size > 1) { if (page < 1) { page = 1; } results = list.Skip((page - 1) * size).Take(size).ToList(); } return(results.AsQueryable()); }
public CatChargeAddOrUpdateModel GetChargeById(Guid id) { CatChargeAddOrUpdateModel returnCharge = new CatChargeAddOrUpdateModel(); var charge = DataContext.Get(x => x.Id == id).FirstOrDefault(); var listChargeDefault = chargeDefaultRepository.Get(x => x.ChargeId == id).ToList(); returnCharge.Charge = charge; // Update permission ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); var permissionRangeWrite = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write); BaseUpdateModel baseModel = new BaseUpdateModel { UserCreated = returnCharge.Charge.UserCreated, CompanyId = returnCharge.Charge.CompanyId, DepartmentId = returnCharge.Charge.DepartmentId, OfficeId = returnCharge.Charge.OfficeId, GroupId = returnCharge.Charge.GroupId }; returnCharge.Permission = new PermissionAllowBase { AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser), }; returnCharge.ListChargeDefaultAccount = listChargeDefault; return(returnCharge); }
public IActionResult Delete(int id) { PermissionRange permissionRange; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingEcusConnection); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); bool isAllowDelete = ecusConnectionService.CheckAllowPermissionAction(id, permissionRange); if (isAllowDelete == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } ChangeTrackerHelper.currentUser = currentUser.UserID; var hs = ecusConnectionService.Delete(x => x.Id == id); var message = HandleError.GetMessage(hs, Crud.Delete); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public IQueryable <SetEcusConnectionModel> Paging(SetEcusConnectionCriteria criteria, int pageNumber, int pageSize, out int totalItems) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingEcusConnection); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { totalItems = 0; return(null); } IQueryable <SetEcusConnectionModel> list = QueryPermission(criteria, rangeSearch); if (list == null) { totalItems = 0; return(null); } totalItems = list.Count(); if (pageSize > 1) { if (pageNumber < 1) { pageNumber = 1; } list = list.Skip((pageNumber - 1) * pageSize).Take(pageSize).OrderByDescending(x => x.DatetimeModified); } return(list); }
public IQueryable <sp_GetCatPlace> QueryExport(CatPlaceCriteria criteria) { IQueryable <sp_GetCatPlace> data = null; if (criteria.PlaceType == CatPlaceTypeEnum.Warehouse) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catWarehouse); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { return(null); } data = QueryByPermission(criteria, rangeSearch); } else if (criteria.PlaceType == CatPlaceTypeEnum.Port) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPortindex); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { return(null); } data = QueryByPermission(criteria, rangeSearch); } else { data = Query(criteria); } return(data); }
public IActionResult GetTariff(Guid tariffId) { PermissionRange permissionRange; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Detail); bool isAllowDelete = tariffService.CheckAllowPermissionAction(tariffId, permissionRange); if (isAllowDelete == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } var result = new TariffModel(); result.setTariff = tariffService.GetTariffById(tariffId); result.setTariffDetails = tariffService.GetListTariffDetailByTariffId(tariffId)?.OrderBy(x => x.DatetimeCreated).ToList(); if (result == null) { return(Ok(new ResultHandle { Status = false, Message = "Không tìm thấy Tariff", Data = result })); } else { return(Ok(new ResultHandle { Status = true, Message = "Success", Data = result })); } }
private int CheckForbitUpdate(string action) { var permissionRange = PermissionExtention.GetPermissionRange(action); var modelCheckUpdate = new BaseUpdateModel { UserCreated = currentUser.UserID, GroupId = currentUser.GroupId, DepartmentId = currentUser.DepartmentId, OfficeId = currentUser.OfficeID, CompanyId = currentUser.CompanyID }; return(PermissionExtention.GetPermissionCommonItem(modelCheckUpdate, permissionRange, currentUser)); }
public int CheckDeletePermission(string id) { var detail = Get(x => x.Id == id).FirstOrDefault(); var salemans = salemanRepository.Get(x => x.PartnerId == id).ToList(); ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default var permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); int code = GetPermissionToDelete(new ModelUpdate { GroupId = detail.GroupId, OfficeId = detail.OfficeId, CompanyId = detail.CompanyId, DepartmentId = detail.DepartmentId, UserCreator = detail.UserCreated, Salemans = salemans, PartnerGroup = detail.PartnerGroup }, permissionRange); return(code); }
public IActionResult CheckAllowDelete(Guid id) { var charge = catChargeService.First(x => x.Id == id); if (charge == null) { return(Ok(false)); } ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); PermissionRange permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); return(Ok(catChargeService.CheckAllowPermissionAction(id, permissionRange))); }
public IActionResult Update(SetEcusConnectionModel model) { PermissionRange permissionRange; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingEcusConnection); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); if (permissionRange == PermissionRange.None) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } bool code = ecusConnectionService.CheckAllowPermissionAction(model.Id, permissionRange); if (code == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } var existedMessage = CheckExist(model); if (existedMessage != null) { return(BadRequest(new ResultHandle { Status = false, Message = existedMessage })); } model.DatetimeModified = DateTime.Now; model.UserModified = currentUser.UserID; model.GroupId = currentUser.GroupId; model.DepartmentId = currentUser.DepartmentId; model.OfficeId = currentUser.OfficeID; model.CompanyId = currentUser.CompanyID; var hs = ecusConnectionService.Update(model, x => x.Id == model.Id); var message = HandleError.GetMessage(hs, Crud.Update); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public IQueryable <CatChargeModel> QueryExport(CatChargeCriteria criteria) { IQueryable <CatChargeModel> data = null; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { return(data); } data = QueryByPermission(criteria, rangeSearch); return(data); }
public override HandleState Add(CatPartnerModel entity) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default var permissionRangeWrite = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); if (permissionRangeWrite == PermissionRange.None) { return(new HandleState(403, "")); } var partner = mapper.Map <CatPartner>(entity); partner.DatetimeCreated = DateTime.Now; partner.DatetimeModified = DateTime.Now; partner.UserCreated = partner.UserModified = currentUser.UserID; partner.Active = true; partner.GroupId = currentUser.GroupId; partner.DepartmentId = currentUser.DepartmentId; partner.OfficeId = currentUser.OfficeID; partner.CompanyId = currentUser.CompanyID; var hs = DataContext.Add(partner); if (hs.Success) { if (entity.SaleMans.Count() > 0) { var salemans = mapper.Map <List <CatSaleman> >(entity.SaleMans); salemans.ForEach(x => { x.Id = Guid.NewGuid(); x.PartnerId = partner.Id; x.CreateDate = DateTime.Now; x.UserCreated = currentUser.UserID; //x.CompanyId = currentUser.CompanyID; //x.OfficeId = currentUser.OfficeID; //x.GroupId = currentUser.GroupId; //x.DepartmentId = currentUser.DepartmentId; }); partner.SalePersonId = salemans.FirstOrDefault().SaleManId.ToString(); DataContext.Update(partner, x => x.Id == partner.Id); salemanRepository.Add(salemans); } DataContext.SubmitChanges(); salemanRepository.SubmitChanges(); ClearCache(); Get(); SendMail.Send("Confirm Add Partner", webUrl.Value.Url.ToString() + "/en/#/home/catalogue/partner-data/detail/" + entity.Id, "*****@*****.**", null, null); } return(hs); }
public List <CatPlaceViewModel> Paging(CatPlaceCriteria criteria, int page, int size, out int rowsCount) { IQueryable <sp_GetCatPlace> data = null; List <CatPlaceViewModel> results = null; if (criteria.PlaceType == CatPlaceTypeEnum.Warehouse) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catWarehouse); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { rowsCount = 0; return(null); } data = QueryByPermission(criteria, rangeSearch); } else if (criteria.PlaceType == CatPlaceTypeEnum.Port) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPortindex); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { rowsCount = 0; return(null); } data = QueryByPermission(criteria, rangeSearch); } else { data = Query(criteria); } rowsCount = data.Select(x => x.ID).Count(); if (rowsCount == 0) { return(results); } if (size > 1) { data = data.OrderByDescending(x => x.DatetimeModified); if (page < 1) { page = 1; } data = data.Skip((page - 1) * size).Take(size); } results = GetCulturalData(data).ToList(); return(results); }
public IActionResult UpdateTariff(TariffModel model) { PermissionRange permissionRange; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); if (permissionRange == PermissionRange.None) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } bool code = tariffService.CheckAllowPermissionAction(model.setTariff.Id, permissionRange); if (code == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } if (!ModelState.IsValid) { return(BadRequest()); } var checkData = tariffService.CheckExistsDataTariff(model); if (!checkData.Success) { return(Ok(new ResultHandle { Status = checkData.Success, Message = checkData.Exception.Message.ToString(), Data = checkData.Code })); } model.setTariff.UserModified = currentUser.UserID; var hs = tariffService.UpdateTariff(model); var message = HandleError.GetMessage(hs, Crud.Update); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value, Data = model }; return(Ok(result)); }
public IActionResult CheckAllowDetail(int id) { PermissionRange permissionRange; ICurrentUser _user = null; SetEcusConnectionModel ecus = ecusConnectionService.Get(x => x.Id == id).FirstOrDefault(); if (ecus == null) { return(Ok(false)); } _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingEcusConnection); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Detail); return(Ok(ecusConnectionService.CheckAllowPermissionAction(id, permissionRange))); }
public IActionResult CheckAllowDelete(Guid id) { PermissionRange permissionRange; ICurrentUser _user = null; var result = new TariffModel(); result.setTariff = tariffService.GetTariffById(id); if (result.setTariff == null) { return(Ok(false)); } _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); return(Ok(tariffService.CheckAllowPermissionAction(id, permissionRange))); }
public CatPlaceModel GetDetail(Guid id) { ICurrentUser _user = null; CatPlace data = DataContext.First(x => x.Id == id); if (data == null) { return(null); } CatPlaceModel result = mapper.Map <CatPlaceModel>(data); if (data.PlaceTypeId == CatPlaceTypeEnum.Warehouse.ToString()) { _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catWarehouse); } if (data.PlaceTypeId == CatPlaceTypeEnum.Port.ToString()) { _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPortindex); } if (data.PlaceTypeId == CatPlaceTypeEnum.Province.ToString() || data.PlaceTypeId == CatPlaceTypeEnum.District.ToString() || data.PlaceTypeId == CatPlaceTypeEnum.Ward.ToString()) { _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catLocation); } var permissionRangeWrite = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write); BaseUpdateModel baseModel = new BaseUpdateModel { UserCreated = result.UserCreated, CompanyId = result.CompanyId, DepartmentId = result.DepartmentId, OfficeId = result.OfficeId, GroupId = result.GroupId }; result.Permission = new PermissionAllowBase { AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser), }; return(result); }
public CatPartnerModel GetDetail(string id) { var queryDetail = Get(x => x.Id == id).FirstOrDefault(); var salemans = salemanRepository.Get(x => x.PartnerId == id).ToList(); ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default var permissionRangeWrite = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); var permissionRangeDelete = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); int checkDelete = GetPermissionToDelete(new ModelUpdate { GroupId = queryDetail.GroupId, OfficeId = queryDetail.OfficeId, CompanyId = queryDetail.CompanyId, UserCreator = queryDetail.UserCreated, Salemans = salemans, PartnerGroup = queryDetail.PartnerGroup }, permissionRangeDelete); queryDetail.Permission = new PermissionAllowBase { AllowUpdate = GetPermissionDetail(permissionRangeWrite, salemans, queryDetail), AllowDelete = checkDelete == 403 ? false : true }; return(queryDetail); }
public IActionResult Delete(Guid id) { PermissionRange permissionRange; ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff); permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); bool isAllowDelete = tariffService.CheckAllowPermissionAction(id, permissionRange); if (isAllowDelete == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } //Check exists tariff & status tariff var checkStatus = tariffService.Get(x => x.Id == id).FirstOrDefault(); if (checkStatus == null) { return(Ok(new ResultHandle { Status = false, Message = "Not found tariff" })); } else { if (checkStatus.Status == true) { return(Ok(new ResultHandle { Status = false, Message = "Not allowed delete tariff" })); } } var hs = tariffService.DeleteTariff(id); var message = HandleError.GetMessage(hs, Crud.Delete); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value }; return(Ok(result)); }
public IActionResult ConvertExistedClearancesToJobs([FromBody] List <OpsTransactionClearanceModel> list) { currentUser = PermissionExtention.GetUserMenuPermission(currentUser, Menu.opsCustomClearance); var permissionRange = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write); if (permissionRange == PermissionRange.None) { return(Forbid()); } HandleState hs = transactionService.ConvertExistedClearancesToJobs(list); var message = HandleError.GetMessage(hs, Crud.Insert); ResultHandle result = new ResultHandle { Status = hs.Success, Message = message }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public SetEcusConnectionModel GetConnectionDetails(int id) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingEcusConnection); var permissionRangeWrite = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write); var data = Get(x => x.Id == id); if (data == null) { return(null); } var result = data.FirstOrDefault(); var users = userRepository.Get(); result.Username = users.FirstOrDefault(x => x.Id == result.UserId)?.Username; result.UserCreatedName = users.FirstOrDefault(x => x.Id == result.UserCreated)?.Username; result.UserModifiedName = users.FirstOrDefault(x => x.Id == result.UserModified)?.Username; BaseUpdateModel baseModel = new BaseUpdateModel { UserCreated = result.UserCreated, CompanyId = result.CompanyId, DepartmentId = result.DepartmentId, OfficeId = result.OfficeId, GroupId = result.GroupId }; result.Permission = new PermissionAllowBase { AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser), }; return(result); }
public IActionResult Delete(Guid id) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); PermissionRange permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Delete); if (!catChargeService.CheckAllowPermissionAction(id, permissionRange)) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } var hs = catChargeService.DeleteCharge(id); var message = HandleError.GetMessage(hs, Crud.Delete); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public IActionResult Update(CatChargeAddOrUpdateModel model) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); PermissionRange permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); if (permissionRange == PermissionRange.None || !catChargeService.CheckAllowPermissionAction(model.Charge.Id, permissionRange)) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } if (!ModelState.IsValid) { return(BadRequest()); } var checkExistMessage = CheckExist(model.Charge.Id, model); if (checkExistMessage.Length > 0) { return(BadRequest(new ResultHandle { Status = false, Message = checkExistMessage })); } var hs = catChargeService.UpdateCharge(model); var message = HandleError.GetMessage(hs, Crud.Update); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public IQueryable <CatPartnerViewModel> Paging(CatPartnerCriteria criteria, int page, int size, out int rowsCount) { var data = QueryPaging(criteria); if (data == null) { rowsCount = 0; return(null); } var salemans = salemanRepository.Get().ToList(); ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default PermissionRange rangeSearch = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.List); switch (rangeSearch) { case PermissionRange.None: data = null; break; case PermissionRange.All: break; case PermissionRange.Owner: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) || x.UserCreated == currentUser.UserID).ToList(); } else { data = data.Where(x => x.UserCreated == currentUser.UserID).ToList(); } break; case PermissionRange.Group: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.GroupId == currentUser.GroupId && (x.DepartmentId == currentUser.DepartmentId) && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.GroupId == currentUser.GroupId && x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Department: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.DepartmentId == currentUser.DepartmentId && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Office: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Company: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; } if (data == null) { rowsCount = 0; return(null); } rowsCount = data.Select(x => x.Id).Count(); IQueryable <CatPartnerViewModel> results = null; if (size > 1) { if (page < 1) { page = 1; } results = data.OrderByDescending(x => x.DatetimeModified).Skip((page - 1) * size).Take(size).AsQueryable(); } return(results); }
public IQueryable <CatPartnerViewModel> QueryExport(CatPartnerCriteria criteria) { var data = QueryPaging(criteria); if (data == null) { return(null); } var salemans = salemanRepository.Get().ToList(); ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default PermissionRange rangeSearch = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.List); switch (rangeSearch) { case PermissionRange.None: data = null; break; case PermissionRange.All: break; case PermissionRange.Owner: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) || x.UserCreated == currentUser.UserID).ToList(); } else { data = data.Where(x => x.UserCreated == currentUser.UserID).ToList(); } break; case PermissionRange.Group: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.GroupId == currentUser.GroupId && (x.DepartmentId == currentUser.DepartmentId) && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.GroupId == currentUser.GroupId && x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Department: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.DepartmentId == currentUser.DepartmentId && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Office: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; case PermissionRange.Company: if (criteria.PartnerGroup.ToString() == DataEnums.CustomerPartner || criteria.PartnerGroup == 0) { data = data.Where(x => (x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID || salemans.Any(y => y.SaleManId == currentUser.UserID && y.PartnerId.Equals(x.Id)) ).ToList(); } else { data = data.Where(x => (x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID ).ToList(); } break; } if (data == null) { return(null); } return(data.AsQueryable()); }
public HandleState Update(CatPartnerModel model) { var listSalemans = salemanRepository.Get(x => x.PartnerId == model.Id).ToList(); ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default var permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write); int code = GetPermissionToUpdate(new ModelUpdate { UserCreator = model.UserCreated, Salemans = listSalemans, PartnerGroup = model.PartnerGroup }, permissionRange, null); if (code == 403) { return(new HandleState(403, "")); } var entity = mapper.Map <CatPartner>(model); entity.DatetimeModified = DateTime.Now; entity.UserModified = currentUser.UserID; entity.GroupId = currentUser.GroupId; entity.CompanyId = currentUser.CompanyID; entity.OfficeId = currentUser.OfficeID; entity.DepartmentId = currentUser.DepartmentId; if (entity.Active == false) { entity.InactiveOn = DateTime.Now; } if (model.SaleMans.Count > 0) { entity.SalePersonId = model.SaleMans.FirstOrDefault().SaleManId.ToString(); } var hs = DataContext.Update(entity, x => x.Id == model.Id); if (hs.Success) { var hsoldman = salemanRepository.Delete(x => x.PartnerId == model.Id && !model.SaleMans.Any(sale => sale.Id == x.Id)); var salemans = mapper.Map <List <CatSaleman> >(model.SaleMans); foreach (var item in model.SaleMans) { if (item.Id == Guid.Empty) { item.Id = Guid.NewGuid(); item.PartnerId = entity.Id; item.CreateDate = DateTime.Now; item.UserCreated = currentUser.UserID; //item.CompanyId = currentUser.CompanyID; //item.OfficeId = currentUser.OfficeID; //item.GroupId = currentUser.GroupId; //item.DepartmentId = currentUser.DepartmentId; salemanRepository.Add(item); } else { item.ModifiedDate = DateTime.Now; item.UserModified = currentUser.UserID; salemanRepository.Update(item, x => x.Id == item.Id); } } salemanRepository.SubmitChanges(); ClearCache(); Get(); } return(hs); }
public IQueryable <CatChargeModel> Paging(CatChargeCriteria criteria, int page, int size, out int rowsCount) { ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge); var rangeSearch = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.List); if (rangeSearch == PermissionRange.None) { rowsCount = 0; return(null); } Expression <Func <CatCharge, bool> > query = null; if (string.IsNullOrEmpty(criteria.All)) { query = x => (x.ChargeNameEn ?? "").IndexOf(criteria.ChargeNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.ChargeNameVn ?? "").IndexOf(criteria.ChargeNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.Code ?? "").IndexOf(criteria.Code ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.Type ?? "").IndexOf(criteria.Type ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.ServiceTypeId ?? "").IndexOf(criteria.ServiceTypeId ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.Active == criteria.Active || criteria.Active == null) ; } else { query = x => ((x.ChargeNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.ChargeNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.Code ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.Type ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.ServiceTypeId ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) && (x.Active == criteria.Active || criteria.Active == null); } // Query with Permission Range. switch (rangeSearch) { case PermissionRange.Owner: query = query.And(x => x.UserCreated == currentUser.UserID && x.CompanyId == currentUser.CompanyID); break; case PermissionRange.Group: query = query.And(x => (x.GroupId == currentUser.GroupId && x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID); break; case PermissionRange.Department: query = query.And(x => (x.DepartmentId == currentUser.DepartmentId && x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID); break; case PermissionRange.Office: query = query.And(x => (x.OfficeId == currentUser.OfficeID && x.CompanyId == currentUser.CompanyID) || x.UserCreated == currentUser.UserID); break; case PermissionRange.Company: query = query.And(x => x.CompanyId == currentUser.CompanyID || x.UserCreated == currentUser.UserID); break; default: break; } var data = DataContext.Paging(query, page, size, x => x.DatetimeModified, false, out rowsCount); var datamap = data.ProjectTo <CatChargeModel>(mapper.ConfigurationProvider); return(datamap); }