/// <summary> /// ��������Ϣ��������Ϣ /// </summary> private void BuildPropertyColumns() { PropertyInfo[] props = TargetType.GetProperties(FLAGS); foreach (PropertyInfo prop in props) { object[] colAttrs = prop.GetCustomAttributes(typeof(ColumnMappingAttribute), true); if (colAttrs.Length == 1) { ColumnMappingAttribute cma = colAttrs[0] as ColumnMappingAttribute; Column column = new PropertyColumn(cma, prop); if (column.IsPrimaryKey) { this.primaryColumns.Add(column); } this.columns.Add(column); } object[] relationReflectAttrs = prop.GetCustomAttributes(typeof(RelationReflectMappingAttribute), true); object[] relationFieldAttrs = prop.GetCustomAttributes(typeof(RelationFieldMappingAttribute), true); if (relationReflectAttrs.Length == 1 && relationFieldAttrs.Length == 1) { RelationReflectMappingAttribute rrMapping = relationReflectAttrs[0] as RelationReflectMappingAttribute; RelationFieldMappingAttribute rfMapping = relationFieldAttrs[0] as RelationFieldMappingAttribute; RelationDef def = null; for (int j = 0; j < relationDefs.Count; j++) { def = (RelationDef)relationDefs[j]; if ((def.TabelAlias == rrMapping.TableAlias) && (def.SourceTableAlias == rrMapping.SourceTableAlias)) { break; } def = null; } if (def == null) { def = new RelationDef(rrMapping.TableName, rrMapping.SourceTableName); def.TabelAlias = rrMapping.TableAlias; def.SourceTableAlias = rrMapping.SourceTableAlias; def.JoinType = TypeHelper.TableJOINTypeToString(rrMapping.JoinType); relationDefs.Add(def); } RelationDetail detail = new RelationDetail(rfMapping.FieldName, rfMapping.SourceFieldName); detail.Compare = rfMapping.Compare; def.RelationDetails.Add(detail); } } }
public ActionResult AddRelationDetails(RelationDetailsViewModel model) { model = RelDetailsModel(model); try { if (ModelState.IsValid) { var maxCount = _unitOfWork.RelationTypeCountRepository.GetAll(x => x.EmpId == model.EmpId && x.RelTypeId == model.RelTypeId).FirstOrDefault(); int relCount = 0; //If there hasn't any record according to this empId and relId, Insert Record to DB_RelationTypeCount and get maximum count for relevant empId and relId if (maxCount == null) { RelationTypeCount count = new RelationTypeCount() { EmpId = model.EmpId, RelTypeId = model.RelTypeId, MaxCount = 1 }; _unitOfWork.RelationTypeCountRepository.Insert(count); if (_unitOfWork.Save() <= 0) { TempData[MessaageEnum.message.ToString()] = Messages._failed; //return RedirectToAction("RelDetailsIndex"); return(View("RelDetailsIndex", model)); } relCount = 1; } else { relCount = (int)maxCount.MaxCount; } var existObj = _unitOfWork.RelationDetailsRepository.GetAll(x => x.EmpId == model.EmpId && x.RelationTypeId == model.RelTypeId).ToList(); //If maximum Count is less than counts of db records of relevant empId and relId, Then Insert if (existObj.Count < relCount) { bool hasName = false; //Check whether relation name is already exist or not foreach (var item in existObj) { if (item.RelationName.ToUpper() == model.RelName.ToUpper()) { hasName = true; } } if (!hasName) { RelationDetail detail = new RelationDetail() { EmpId = model.EmpId, RelationTypeId = model.RelTypeId, RelationName = model.RelName }; _unitOfWork.RelationDetailsRepository.Insert(detail); } else { TempData[MessaageEnum.message.ToString()] = "danger_This relation name is already exist"; return(View("RelDetailsIndex", model)); } } else { TempData[MessaageEnum.message.ToString()] = "danger_You can add maximum " + relCount + ", from this relation type"; return(View("RelDetailsIndex", model)); //ModelState.AddModelError("RelTypeId", "You can add maximum " + relCount + ", from this relation type"); } if (_unitOfWork.Save() > 0) { TempData[MessaageEnum.message.ToString()] = Messages._sucess; return(RedirectToAction("RelDetailsIndex")); } else { TempData[MessaageEnum.message.ToString()] = Messages._failed; return(View("RelDetailsIndex", model)); } } } catch (Exception ex) { throw; } return(View("RelDetailsIndex", model)); }