protected Request ConvertToRequest(RequestModel <TUserModel> requestModel, Action <RequestUserAssoc, TUserModel> requestUserAssocAddedCallback = null) { requestModel.Users.ForEach(r => r.Snp = r.Snp.Trim()); requestModel.Users = ClearUsersDuplicates(requestModel.Users); var request = new Request { IdRequest = requestModel.IdRequest, IdRequestType = requestModel.IdRequestType, Description = requestModel.Description, RequestUserAssoc = new List <RequestUserAssoc>() }; foreach (var user in requestModel.Users) { var requestUser = new RequestUser { Snp = user.Snp, Login = user.Login, Post = user.Post, Department = user.Department, Unit = user.Unit, Office = user.Office, Phone = user.Phone }; var requestUserAssoc = new RequestUserAssoc { RequestUser = requestUser, Request = request, Description = user.Description }; request.RequestUserAssoc.Add(requestUserAssoc); if (requestUserAssocAddedCallback != null) { requestUserAssocAddedCallback(requestUserAssoc, user); } if (user.Rights != null) { requestUserAssoc.RequestUserRightAssocs = new List <RequestUserRightAssoc>(); foreach (var right in user.Rights) { var requestUserRightAssoc = new RequestUserRightAssoc { RequestUserAssoc = requestUserAssoc, Descirption = right.Description, IdRequestRightGrantType = right.IdRequestRightGrantType, IdResourceRight = right.IdResourceRight }; requestUserAssoc.RequestUserRightAssocs.Add(requestUserRightAssoc); } } } return(request); }
protected RequestUserRightModel RequestUserRightModelBy(RequestUserRightAssoc rightAssoc) { return(new RequestUserRightModel { Description = rightAssoc.Descirption, IdResourceRight = rightAssoc.IdResourceRight, ResourceRightName = rightAssoc.ResourceRight.Name, ResourceRightDescription = rightAssoc.ResourceRight.Description, IdRequestRightGrantType = rightAssoc.IdRequestRightGrantType, RequestRightGrantTypeName = rightAssoc.RequestRightGrantType.Name, IdResource = rightAssoc.ResourceRight.IdResource, ResourceName = rightAssoc.ResourceRight.Resource.Name, ResourceDescription = rightAssoc.ResourceRight.Resource.Description }); }